1

I have been trying to figure out this for a while but no success-

I have this site structure http://example.com/catalog/current/sub-folders/.. The result should hide the folder "current" so that the paths look like http://example.com/catalog/sub-folders/

This is what I have so far-

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+current/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^current/)^(.*)$ /current/$1 [L,NC]

when I place this .htaccess to the root and go to http://example.com/catalog/sub-folders/, it try to look for /current/catalog/sub-folders/

Any help to approach this problem will be highly appreciated.

2 Answers 2

1

Keep your code like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(catalog)/current/(\S*) [NC]
RewriteRule ^ %1/%2 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(catalog)/((?!current/).*)$ $1/current/$2 [L,NC]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+)$ $1.php [L]
Sign up to request clarification or add additional context in comments.

5 Comments

Tried this but does not seem to do anything
What URL did you try to test and what is location of this .htaccess? Are there more rules?
I put the .htaccess at the root of the server "/" No there are not other rules. The url I tried is localhost/catalog/current/test-1/
this works. thank you so much!! One last question- how can this be modified so that path like localhost/catalog/current/ or simply localhost/catalog/ also rewrites to whats inside "current"?
thanks for the updates. I tried that and it shows the contents of /catalog when I use localhost/catalog/current/ or localhost/catalog/ but not what is in 'current'.
0

Try making the last rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^hsc-bulletin/)^(.*)$ /current/$1 [L,NC]

This instead:

RewriteCond %{REQUEST_URI} !^/current/
RewriteRule ^(?!hsc-bulletin/)(.*)$ /current/$1 [L,NC]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.