Trying to add a trailing slash to every link. For instance:
http://testsite.com/products
should 301 redirect to:
http://testsite.com/products/
etc. But how? Here is my current .htaccess:
AddDefaultCharset utf-8
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_URI} !\.(ico|css|js|txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !^/admin
RewriteCond %{REQUEST_FILENAME} !^/migrate
RewriteCond %{REQUEST_FILENAME} !^/install
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
Related
I have a problem with the .htaccess file. I have it configured in this way.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/$ index.php?controller=$1 [L]
Every time I access http://localhost/mvc3/contacto/ I'm accessing http://localhost/mvc3/index.php?controller=contacto, up there it is correct but if the friendly URL I remove the final character / (http://localhost/mvc3/contacto) it returns me to the root page (wampserver server).
Here is explained in video of the problem, what would be happening?
Video ▶️ http://recordit.co/FfXHww1xCv
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?controller=$1 [L]
Remove slash from the rewrite rule and it should work.
may below changes in .htaccess will be helpful for you
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ index.php?controller=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
Dears,
I want to add / at the end of each url of site, below is what i found online, it works good, but in wp-admin it gives me wp-admin/index.php/index.php/. Like everytime i click on dashboard it will add /index.php/
code from htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
</IfModule>
Please advise.
Thanks
Keep redirect rule before your default WP rule:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Make sure to use a new browser for your testing.
For now i have all requests to my domain to go through /index.php
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
However i want to add an exception. If the request goes to folder "/this_specific_folder/" then it should go for "/this_specific_folder/index.php" instead of "/index.php", without breaking the current existing logic.
How can i achieve this?
You can have it this way:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(this_specific_folder)(?:/.*)?$ /$1/index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
My mod_rewrite is working excellent, but it's not recognizing anything after for example /calgary/
So, if I go to /calgary/login.php and it is only seeing the index.php page? It won't recognize the /login.php page?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /city_name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/?$ /city_name/index.php?page=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/?$2.php?page=$1 [L,QSA]
</IfModule>
You need to swap those 2 rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /city_name
# This used to be the 2nd rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
# there used to be a "?" here, remove it ----v
RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/$2.php?page=$1 [L,QSA]
# this used to be the first rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/?$ /city_name/index.php?page=$1 [L,QSA]
</IfModule>
The less restrictive rule (the one that matches (.*)/?$) will match /calgary/login.php outright before the second set of rules gets to do its thing, which seems to be rewritten to /city_name/?login.php?page=calgary.
Is that really what you want? There are two ? in the target there. Maybe you only want /city_name/$2.php?page=$1?
Try removing the 'L' from the first rewrite rule, this tells Apache to stop processing further rules if a match is found.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /city_name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/?$ /city_name/index.php?page=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/?$2.php?page=$1 [L,QSA]
</IfModule>
http://www.example.com/justridesbeta/jstride/vehicle
to
http://www.example.com/justridesbeta/addride
using htaccess.
Currently using
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
RewriteRule ^[a-zA-Z0-9]+$ justridesbeta/jstride/vehicle
</IfModule>
if ($_SERVER['REQUEST_URI'] == '/justridesbeta/jstride/vehicle')
{
header("Location: http://www.example.com/justridesbeta/addride");
exit;
}
if you really need that