1

I have the following code in my htaccess file:

Options -Indexes RewriteEngine On # Redirect external .php requests to extension less url RewriteCond %{THE_REQUEST} ^(.+)\.html([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}/foo/$1 [R=301,L] # Resolve .html file for extension less html urls RewriteRule ^([^/.]+)$ $1.html [L] 

That work fine when I go to www.mydomain.com/foo/index whithout .html. I want force trailing Slash at the end of index but i don't know how

Does anyone know how to modify my code to make the trailing slash work ?

Thanks!

1

2 Answers 2

1

To add a trailing slash to your extension less html urls, You need to modify your both of the rules.

In the first rule, we add a trailing at the end of the target url so that a slash is added to all .html requests.

and in the second rule we add a trailing slash at the end of the regex pattern to accept a request with a trailing slash.

Options -Indexes RewriteEngine On # Redirect external .php requests to extension less url RewriteCond %{THE_REQUEST} ^(.+)\.html([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}/foo/$1/ [R=301,L] # Resolve .html file for extension less html urls RewriteRule ^([^/.]+)/?$ $1.html [L] 

Clear your browser's before testing this! (Hope,this helps!)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help ! I will try your solution
1

I modified my code for this:

Options -Indexes RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^([^/]+)/$ $1.html RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.html(\?[^\ ]*)?\ HTTP/ RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://%{HTTP_HOST}/fr/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ http://%{HTTP_HOST}/fr/$1/ [R=301,L] 

It works well

1 Comment

Now I would hide in the url the fr folder. I would like your help because I did not find anything conclusive on the subject. Thanks thanks !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.