Redirect htaccess

I need to help with redirect my page.

For example I have websites https://example.com. I need to move content from https://example.com to https://example.com/blog. That is not problem and I do that with a change home_page URL. That work pretty well. But Now I need to add redirect from old https://example.com to https://xmpl.com. I want to do with .htaccess but that does not work. Can you help me guys?

Here are some of my attempts of this but both does not work.

RewriteEngine On RewriteRule https://example.com/ https://xmpl.com/ [L,R=302] 

or

RewriteEngine On Redirect 302 https://example.com/ https://xmpl.com/ 

Thank you for your help and time guys.

.htaccess redirects disappeared after re-saving permalinks

Hello and sorry for these newbie questions… I want my wordpress website to load with https+non-www and without traling slashes. I put the following code in .htaccess file:

<IfModule mod_rewrite.c>  RewriteEngine On  # Remove trailing slash from non-filepath urls  RewriteCond %{REQUEST_URI} /(.+)/$    RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^ https://domain.com/%1 [R=301,L]  # Force HTTPS and remove WWW  RewriteCond %{HTTP_HOST} ^www\.(.*)$   [OR,NC]  RewriteCond %{https} off    RewriteRule ^(.*)$   https://domain.com/$  1 [R=301,L] </IfModule> 
  1. These rules work fine but I can’t remove multiple slashes after domain. The website loads: "https://domain.com/////" and I want it to redirect to "https://domain.com"

  2. Also, these rules work if they are only in the beginning of the htaccess file and when I re-save the permalinks the rules disappear…

Could you help me, please

Rewrite a folder name using .htaccess don’t want to work

I am wondering, why folder renaming doesn’t work. RewriteRule ^pl/(.*) public/$ 1

Lets say I have a url like:

site.com/public/index.html 

Now I want to rewrite the url to

site.com/pl/index.html 

"pl" is not a folder rather just a name!

The rest works fine. Why just that one rule doesn’t work?

my .htaccess

RewriteEngine on RewriteRule ^dekoracyjne.html$   decorative.php [NC,L] RewriteRule ^pl/(.*) public/$  1 RewriteRule ^dekoracyjne/(.*) decorative/$  1 RewriteRule ^techniczne.html$   architectural.php [NC,L] RewriteRule ^techniczne/(.*) architectural/$  1 RewriteRule ^show.html/([-\w]+)$   show.php?id=$  {products:$  1} [L] RewriteRule ^p.html$   product_configurator.php [NC,L] RewriteRule ^show_c\.html/([-*\w]+)$   show_c.php?cat=$  {catcolors:$  1} [L] RewriteRule ^(product_configurator)\.html/(\d+)&([-\w]+)$   $  1.php?prometheus_id=$  2&id=$  {products:$  3} [L] RewriteRule ^(ss_c)\.html/(\d+)&([-\w]+)$   $  1.php?prometheus_id=$  2&id=$  {products:$  3} [L] # Rewrite other ".html" requests to ".php" RewriteRule (.+)\.html$   $  1.php [L] 

.htaccess — Trailing slash and characters after file extension

I’ve got some weird usability warnings popping up in my search console for pages which don’t actually exist on my site. It looks like someone is creating 100’s of malformed links to my pages.

Here’s the problem.

Say I have https://example.com/pagename.html

Someone is creating hundreds of links with random text after the filetype like this: https://example.com/pagename.html/randomtext

Strangely, with that malformed URL, part of the page renders, but renders with broken styling for some reason. (Triggering search console warnings for every one of those "pages"). I’m not really sure how or why these broken URLs are rendering at all. My understanding is that this should return a 404 error. But it doesn’t.

So…

I’m trying to solve the problem with .htaccess like this:

RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$   /$  1 [L,R=301] 

That sort of works. It removes the trailing slash from https://example.com/pagename.html/ but it doesn’t fix https://example.com/pagename.html/randomchars

How do I get it to ignore all characters following the file type? (except standard GET strings starting with a ?)

Thanks in advance.

Htaccess Using RewriteMap with a text file

I can’t use link with * Example – http://localhost/photo_gallery/public/show_c.html/color-1* The requested URL was not found on this server. The others work’s color-3, wood, etc.

  1. generated map – map.txt

    title   id color-1* 1 color-1** 2 color-3 3 wood 4 color777 5 color-test 6 
  2. htaccess

    RewriteRule ^show_c.html/([-\w]+)$   show_c.php?cat=$  {catcolors:$  1} [L] 
  3. httpd.conf

    RewriteMap catcolors "txt:C:\wamp\www\photo_gallery\public\maps\map.txt" 

My question. Why the link with * cannot be used.

htaccess force https not working if there is an URI

I’ve never worked with Apache, so I’m a completely newbie.

I have a multihosting account on a provider website, where 3 domain are used. I want to force https connection on a domain, let’s say example.com, which is not the main domain of the hosting plan. What I did is to add an .htaccess file in the path examplecom/public_html, the folder where there are all the file of the website. In the .htaccess I have copy-pasted this strings from the provider guide:

RewriteEngine on RewriteBase / RewriteCond %{HTTPS} !on RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301] 

The website works correctly if I go to a page with an non-empty URI, but it doesn’t on the main page. In example: http://example.com/anypage is correctly redirected to https://www.example.com/anypage, while http://example.com/ is redirected to https://www.example.com/public_html, and can’t understand why.

I’m really confused with my .htaccess config

My directory structure is

- Assets - Dashboard    - index.php    - account.php index.php about.php verify.php 

What i basically want it to be:

  1. Remove the .php extension for example http://example.org/about.php should be http://example.org/about/ (including the trailing slash as well)
  2. If .php is encountered in the URL redirect it back to http://example.org/about/
  3. Instead of having the URL as http://example.org/verify.php?key=123456 it should be http://example.org/verify/123456
  4. Conditions to be met in sub directory as well for example http://example.org/dashboard/ should be the URL instead of http://example.org/dashboard/index.php

My .htaccess file looks like this

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)$   $  1.php [L] RewriteRule ^verify/([0-9a-zA-Z]+)\.php /verify.php?key=$  1 [NC,L]  <FilesMatch "\.(jpg|png|svg|css)$  "> Header set Cache-Control "proxy-revalidate, max-age=0" </FilesMatch>   <Files .htaccess> order allow,deny deny from all </Files>  Options All -Indexes  ErrorDocument 403 /404.html ErrorDocument 404 /404.html ErrorDocument 500 /404.html 

Im really sorry for not giving much clarity.

I’m running it on localhost XAMPP web server.

  • Rule 3 and 4 works absolutely fine!
  • Rule 1 works fine but when it encounters the trailing slash it gives me a 404.
  • Rule 2 doesn’t seem to work.

Removing “index.php?page=” in .htaccess entirely and once and for all

This question has been driving me nuts. There seem to be hundreds of answers online and on various StackExchange websites, but they either remove index.php (keeping ?page=) like this:

Options +FollowSymLinks -MultiViews RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$   index.php?$  1 [L,QSA] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] RewriteRule ^ %1 [R=301,L] 

…or like this:

RewriteBase / RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$   RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC] RewriteRule ^index\.php(.*)$   $  1 [R=301,NS,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$   index.php/$  1 [QSA,L] 

…or remove both but cause the page to not work (not be recognized as a PHP file), like this:

Options -MultiViews RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC] RewriteRule ^ /%1? [R=302,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$   index.php?page=$  1 [L,QSA] 

How the heck do I remove index.php?page= and still get the remaining file/URL to be recognized as a proper PHP file?

How to rewrite URL with PHP variables with htaccess to a normal looking URL?

I have a problem. I want to change an old database website that is not made in WordPress to WordPress. My site uses PHP variables So the URL is originally:

website.com/index.php?tl=1&pg=2&bs=3&hcbs=4&sc1bs=5&sc2bs=6&sc3bs=7&hc=8&blbs=9

But I could rewrite that to a normal looking url:

website.com/1/2/3/4/5/6/7/8/9.php

To do that in the old site I used the following rewrite rules in the .htaccess file:

RewriteEngine on  RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&sc2bs=$  6&sc3bs=$  7&hc=$  8&blbs=$  9 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&sc2bs=$  6&hc=$  7&sc3bs=$  8 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&hc=$  6&sc2bs=$  7 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&hc=$  5&sc1bs=$  6 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hc=$  4&hcbs=$  5 [L] RewriteRule ^(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3 [L] 

But now I am trying to do so in WordPress. WordPress already has some preinstalled rewrite rules:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$   - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> 

But when I try to combine the both in any way the complete wordpress site stops working. Does anyone have an idea how to solve this?

Looking forward for your replies

Greetings

Hanno