Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ HTTP%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
ServerSignature Off
RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]`
Hello I'm struggling really hard with URL closing trailing slash.
RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]
I would like, for example, to force a redirection from www.website.com/cookie-policy to www.website.com/cookie-policy/
Use this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
It will add a / to end of your URLs. Make sure you clear your cache before testing this.
Related
I've been crawling forums for about 2 hours and still haven't found the solution to my problem so I am turning to you guys for help.
My URL looks like this
http://gymbirdz.com/article.php?url=benefits-of-fish-oil
I want it to look like this
http://gymbirdz.com/article/benefits-of-fish-oil
This is my .htaccess request but It does not work and still no luck fixing it :/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?article/([A-Za-z0-9-]+)/?$ /article.php?url=$1 [NC,R=301,L]
Any help is appreciated very much! Thank You
UPDATE
This is how my .htaccess looks from above
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^article/([A-Za-z0-9\-]+)$ article.php?url=$1 [NC,R=301,L,QSA]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} ^www\.gymbirdz\.com$
RewriteRule ^/?$ "http\:\/\/gymbirdz\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^192\.254\.185\.208
RewriteRule (.*) http://www.gymbirdz.com/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
Try this rule your site root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl [NC]
RewriteRule ^ - [F,L]
RewriteCond %{HTTP_HOST} ^www\.gymbirdz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^192\.254\.185\.208$
RewriteRule (.*) http://gymbirdz.com/$1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{THE_REQUEST} /article\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /article/%1? [R=302,L,NE]
RewriteRule ^/?article/([\w-]+)/?$ article.php?url=$1 [NC,QSA,L]
Maybe I don't understand your question, but this is from the documentation:
Syntax: RewriteRule Pattern Substitution [flags]
This is your rule:
RewriteRule ^/?article/([A-Za-z0-9-]+)/?$ /article.php?url=$1 [NC,R=301,L]
It appears that you may have the two arguments reversed. Try something like this instead:
RewriteRule ^article.php?url=([\w-]+) /article/$1 [NC,L,R=301,QSA]
This assumes that the .htaccess file is in the same directory as article.php.
I am implementing friendly URLs on my website.
At the moment I have some rules working but still need help to implement the last ones.
Rules working:
RewriteRule ^SobreNos$ /about.php [L]
RewriteRule ^Contactos$ /contact.php [L]
Rule Working but not as I wanted:
RewriteRule ^catalogo-([a-zA-Z0-9]+)$ catalogo.php?cat=$1
Rule not working:
RewriteRule
^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ product.php?id=$1&ref=$2&cat=$3 [L]
About the 3rd rule, I wanted the friendly URL catalogo/homem and tried to change the - for the / but didn't work.
The 4th rule don´t work at all, with - or the /.
Could be a problem of the server's version? This is the version of the server "Apache ver.2.2.19 (Unix)".
My .htaccess file
RewriteBase /
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^SobreNos$ /about.php [L]
RewriteRule ^Contactos$ /contact.php [L]
RewriteRule ^catalogo-([a-zA-Z0-9]+)$ catalogo.php?cat=$1
RewriteRule
^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ product.php?id=$1&ref=$2&cat=$3 [NC,L]
I have reformatted your file to the following:
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^SobreNos$ about.php [L]
RewriteRule ^Contactos$ contact.php [L]
RewriteRule ^catalogo/([a-z0-9]+)/?$ catalogo.php?cat=$1 [NC,L]
RewriteRule ^products/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/?$ product.php?id=$1&ref=$2&cat=$3 [NC,L]
Here's what I've changed:
Moved your RewriteBase down below RewriteEngin on
Removed the leading slashes in the destinations for each rule (they are not needed because RewriteBase is set)
Removed A-Z from your expressions (because the NC, no case, flag is set)
Used the slash in the 3rd and 4th rules, and appended an optional ending slash.
My test show that everything works properly. The only reason a 404 would be thrown is if the file you are rewriting to (product.php for example) does not exist.
I have the solution for the problem.
Options -Indexes
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ catalogo.php?cat=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/([^/]+)$ catalogo.php?cat=$1&scat=$2 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ product.php?cat=$1&scat=$2&name=$3&id=$4 [L,QSA]
Still have to add a rewrite rule for about.php and contactos.php, but not a huge problem.
We want to redirect every page in Magento to https. We know how to change this in Magento, but we do not know how to do this in our current htaccess? For more information, please see our current htaccess file below, stripped from unnecessary comments.
Current htaccess:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
DirectoryIndex index.php
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{THE_REQUEST} \s+/index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1? [L,R=301,NC,NE]
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteRule ^home/?$ /? [R=301,L,NC]
# ADD WWW TO NONE WWW FOR BOTH HTTPS AND NONE HTTPS
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#REDIRECT ALL .HTML FILES AND ALL .HTML/ FILES WITH TRAILING SLASH
RewriteRule ^google[0-9a-f]+.html$ - [L]
RewriteRule (.+)\.html$ /$1/ [L,R=301]
RewriteRule (.+)\.html\/$ /$1/ [L,R=301]
# ADD TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# TRAILING SLASH CHECK
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
#CHECK IF REDIRECT POINTS TO A VALID FILE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#REWRITE EVERYTHING ELSE TO INDEX.PHP
RewriteRule .* index.php [L]
Solved by adding:
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
Add the below code
RewriteEngine on
after
RewriteCond %{HTTPS} on
RewriteRule ^$ https://%{HTTP_HOST} [L,R]
And goto admin>SYStem>configuration>General>Web>
change all secure url and unsecure to https:
ex:
I want to redirect this php url to the folder.
I always used the settings below. But since the update of apache to 2.4 it doesnt work anymore.
Goal:
example.com/about.php?sub=about or example.com/about.php?sub= should be seen in the browser as example.com/about/
I use the following settings.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(example.com)(:80)? [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
RewriteRule ^about/$ about.php$1 [L]
RewriteRule ^about/([A-Za-z0-9-]+)$ about.php?sub=$1 [L]
This is what I am using now...
I don't see any rule in your code that is making /about.php?sub= to /about.
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(about)\.php(\?sub=[^\s&]*)?\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^about/?$ about.php?sub=about [L,NC,QSA]
RewriteRule ^about/([a-z0-9-]+)/?$ about.php?sub=$1 [L,NC,QSA]
# Add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R]
I'd like to redirect
www.example.com/* to example.com/*
And at the same time redirect
example.com/* to example.com/forum/*
But I also have /wiki/ and /blog/ and /style/, so I don't want to redirect
example.com/style/* to example.com/forum/style/*
This is what I have at the moment, which is not working quite correctly:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/forum/
RewriteRule ^(.*)$ forum/$1 [R=301,L]
Clarification: my question can be asked in a simpler way.
I'd like to redirect an empty REQUEST_URI or /, or a non-existent file only if it is in the root directory to /forum/.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,QSA,L]
RewriteCond %{REQUEST_URI} !^/(wiki|blog|style|forum)
RewriteRule ^(.*)$ http://www.example.com/forum/$1 [R=301,QSA,L]
I would use these rules:
# redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]
# prefix everything but /forum/, /wiki/, /blog/, /style/ with /forum/ and rediret to it
RewriteRule !^(forum|wiki|blog|style)/ /forum%{REQUEST_URI} [L,R=301]
The second rule could additionally be replaced by this one to check the existence of the first path segment for every request.
# check if first segment of requested URI path is either missing
RewriteCond $0 ^$ [OR]
# or cannot be mapped to an existing directory
RewriteCond %{DOCUMENT_ROOT}$0/ !-d
RewriteRule ^[^/]* /forum%{REQUEST_URI} [L,R=301]
I'd say this should work.
RewriteEngine on
RewriteRule ^forum/(.*)$ forum/$1 [L]
RewriteRule ^wiki/(.*)$ wiki/$1 [L]
RewriteRule ^blog/(.*)$ blog/$1 [L]
RewriteRule ^style/(.*)$ style/$1 [L]
RewriteRule ^(.*)$ forum/$1 [L]
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule ^(.*)$ http://example.com/$1
I don't have the answer for everything but for your www/no www problem you could try this :
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ /exemple/$1 [L,R=301]
# Enforce NO www
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^(.*)$ http://exemple.com/$1 [L,R=301]