I've been trying to solve this for some time, and have tried a few suggestions which I found, but none of them seem to work
I would like to try and force a slash at the end of the URL for any page visited on my site, so rather than
www.example.com/about
it forces
www.example.com/about/
My .htaccess looks like
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ local/ [L]
RewriteRule (.*) local/$1 [L]
</IfModule>
Could anyone help?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
try this
Related
I have a small script that creates a url
<a href="index.php?username=<?php echo $user['name']; ?>" >View Profile</a>
The problem is the url shows
http://pimpedryde.com/cars/index.php?username=bimmerguy
I was wanting the url to look more like
http://pimpedryde.com/cars/bimmerguy
I've tried a few htaccess codes without success. Any Ideas?
This is a working example of code igniter Project, Try this one.
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php/$1 [L]
#</IfModule>
Maybe this works
RewriteEngine On
RewriteRule ^http://pimpedryde.com/cars/(.*)=(.*)$ http://pimpedryde.com/cars/$2 [R=301,L]
OR
RewriteRule ^cars/(.*)=(.*)$ http://pimpedryde.com/cars/$2 [R=301,L]
This did it for me.
RewriteRule ^([^\.]+)$ index.php?username=$1 [L]
This is a great little tool for testing: http://htaccess.madewithlove.be/
You are in a sub-folder, so you need the RewriteBase clause, like this:
RewriteEngine On
RewriteBase /cars/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?username=$1 [L]
That should do it.
I am trying to redirect http://example.com/for-sale/?property=1234 to http://example.com/for-sale/property-name/ in .htaccess, using RewriteCond and RewriteRule. This is what I have so far:
RewriteCond %{QUERY_STRING} ^(property=1234)
RewriteRule ^$ /for-sale/property-name/? [R=301,L]
This does not work. I can redirect ?property=1234 to for-sale/property-name/ but how do I get it to work with /for-sale/ in the un-redirected URL? I've tried various combinations of for-sale in the RewriteRule but without success.
Thanks.
All my links are now broken so I would really appreciate some advice. Thanks.
This is a wordpress site, so the first mistake was to do the rewrites after wordpress does its rewrites. Second mistake was in the RewriteRule. Here is the working code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} property=1234$
RewriteRule ^for-sale/?$ /for-sale/property-name/? [R=301,L]
... my other rewrites
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This works. Hope it helps someone else out.
I have a daunting problem with dynamic redirects that I have to do on WordPress website that was before an aspx website.
I am looking for advice for a week now and tried almost everything with different outcomes but none proved successful.
I need to redirect complex URLs such as:
/Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
to something simple like
http://domain.com/folder/
I've used number of ideas including loads from StackOverflow but none seem to tackle this specific example. Using standard Redirect 301 rule will work for as long as I don't have ? in the link. I understand this is beyond the scope of Redirect 301 and I need to use RewriteRule.
I tried this (got this from the excel spreadsheet for dynamic urls redirection):
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
But still on entering the url it yields 404 page.
Here's my .htaccess:
## BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
## messing up
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
</IfModule>
Do I place it correctly? Is the code right? I would appreciate any ideas and clues.
Thanks a million
I have solve the mastery. The code was good just the placing was incorrect. After dozen tries and errors I found the correct formula. I had to amend placing of my redirect rule. Here is how it looks:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://doamin.com/folder/? [R=301,L]
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have a page locally that is /shop but I want it to redirect to /shop/designs
I tried to do it with .htaccess but nothing seems to be working.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/shop/.*$ /shop/designs/ [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas where I am going wrong?
You were almost there, but in htaccess, you cannot use / at the beginning of the path regex.
Change your rule like so:
RewriteEngine On
RewriteRule ^shop$ shop/designs [R=301,L]
I have been using htaccess to remove rewrite certain URLs, however I am looking at something a little more complicated at the moment.
Our website blog (WordPress) used to have links like this:
/blog/postname/1387
However after redoing the website our links are now currently just
/postname
Would it be possible to redirect any uses from /blog/postname/1387 and get rid of the blog and number at the end via htaccess so it just contains the postname? At the moment I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^blog/(.*)/.*$ $1/
</IfModule>
Would love to hear any hints or tips, as this is not actually doing any redirecting, what am I doing wrong?
Let's just do a little cleanup:
<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
#Rewrites are all relative to /
RewriteBase /
#Explicit - If the request is for index.php, do nothing.
RewriteRule ^index\.php$ - [L]
#Conditional – Unless the file or directory specifically exists,
#If the request is for the old style blog URI, redirect to new style and stop.
#Otherwise, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/.*$ $1/ [R=301,L,QSA]
RewriteRule . /index.php [L]
</IfModule>