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.
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]
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]
Related
Hi i want rewrite:
example.com/articles to example.com/?rt=articles
and
example.com/articles/some-title-here to example.com/?rt=articles&title=some-title-here
My code:
RewriteEngine on
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
RewriteRule ^articles/(.*)$ index.php?rt=articles&title=$1 [L,QSA]
First rewrite rule it's working but second doesn't work...
Have it this way:
RewriteEngine on
Options -Indexes
# ignore all files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^articles/(.+)$ index.php?rt=articles&title=$1 [NC,L,QSA]
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
i've removed .php extensions first on my website. then i've forwarded www to non-www version. but there is a problem with that.
my .htaccess file looks like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^188\.166\.104\.194
RewriteRule (.*) http://example.com/$1 [R=301,L]
www forwards to non-www with that .htaccess. that is cool. but the problem is with the other files.
i'm now using: http://example.com/contact instead of: http://example.com/contact.php
but when you try to open http://www.example.com/contact that .htaccess forwards me to http://example.com/contact.php/
how do i fix that?
have a nice day!
Change the order of rules and some refactoring:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.example\.com|188\.166\.104\.194)$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]
Make sure to test is after clearing your browser cache.
I cannot get the clean user profile url to work. I already tried everything!
I want to redirect
http://localhost/test/profile?username=gadgetster
to
http://localhost/test/profile/gadgetster
Here is my attempt:
Options -Indexes -MultiViews +FollowSymlinks
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.+)$ profile.php?username=$1 [L,NC,QSA]
why isn't this working?
Have it like this:
Options -Indexes -MultiViews +FollowSymlinks
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} /profile\.php\?username=([^\s&]+) [NC]
RewriteRule ^ profile/%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^profile/(.+)$ profile.php?username=$1 [L,NC,QSA]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
Make sure there is no .htaccess in /test/profile/.
I'm trying to redirect from /page.html to /page inside of a subdirectory, but it doesn't work.
What I do: http://example.com/subdirectory/page.html
What I get: http://example.com/page
What I want: http://example.com/subdirectory/page
.htacces file:
RewriteEngine On
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
How can I get this to work?
Use this code for .html hiding in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ /$1.html [L]
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
Thanks
I want something like the following:
http://fref.co/anystring
to be rewritten as:
http://fref.co/?q=anystring
This is how far I've gone:
RewriteEngine On
RewriteRule ^(.+)/?$ index.php?q=$1 [NC,L]
This should work for your needs:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Internally redirect http://fref.co/anystring to http://fref.co/?q=anystring
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ /index.php?q=$1 [L]
# Redirect http://fref.co/?q=anystring to http://fref.co/anystring
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(/index\.php|/)\?q=([^\s]+) [NC]
RewriteRule ^ /%2? [R=302,L]