I want to set up 301 redirects in my .htaccess file so URLs like
http://example.com/Foo
http://example.com/Foo/Bar
http://example.com/Foo/Bar/Blah
change to
http://example.com/products/foo
http://example.com/products/foo/bar
http://example.com/products/foo/bar/blah
There are a discrete number of "Foo" cases which I can target with RewriteRule ^Foo, but how to append the "products" part?
First add this line in <VirtualHost> section OR at the end of your httpd.conf file:
RewriteMap lc int:tolower
Then have these rules in .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^(Foo.*)$ /products/${lc:$1} [R=301,L]
R=301 for sending back 301 to browser
L for marking it last rule
Related
I'm using the below htaccess rewrite rules to redirect old url files to the new ones.
The first RewriteRule redirects to new url file if the file path requested is fares/ or airfares/ or anyword-fares/ etc.
The second RewriteRule redirects to new URL file only if the url path requested is flights/.
My 1st question is, did I write them correctly or leave anything out?
2nd question is, can I combine the two RewriteRules into one or use a rewrite condition to combine them into one?
I'm asking because I will be adding more that will redirect to the new url file of airfares-flights/
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^.*fares/(.*)$ /airfares-flights/$1 [R=301,NC,L]
RewriteRule ^flights/(.*)$ /airfares-flights/$1 [R=301,NC,L]
Yes your rules are correct.
Yes both rules can be combined into one.
Use this .htaccess:
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^(?:.*fares|flights)/(.*)$ /airfares-flights/$1 [R=301,NC,L]
I am new to the .htaccess file.
I want to make pretty URLs but the server always gives me 404 or 500 errors.
For example, I want to redirect
http://www.example.com/dir1
to
http://www.example.com/dir1/file1.html
without showing file1.html in the address bar.
I've tried
RedirectRule /dir1/$ /dir1/file1.html but the server says 404.
The .htaccess is in root.
What should I do?
Remember that .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteBase /
RedirectRule ^dir1/?$ dir1/file1.html [L,NC]
OR use this rule in /dir1/.htaccess:
RewriteEngine On
RewriteBase /dir1/
RedirectRule ^/?$ file1.html [L]
This htaccess rule will do the trick.
RewriteEngine On
RewriteBase /
RedirectRule ^dir1/?$ dir1/file1.html [L]
For the record the terminating /? means that you to redirect links with /dir1 and links with /dir1/
I have following urls generated in the html
http://www.xxx.com/page/26/website-design-services?ajax=true
configured .htaccess syntax to read the value of the page id is
# BEGIN Rewrite
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
RewriteRule ^page/([^/]+)/?(.*)$ page.php?section=$1 [QSA,L]
</IfModule>
# END Rewrite
When i call the php file to do the get like below it returns only ajax part in the GET array. see below in page.php
print_r($_GET);
$url = $_GET['section'];
output is
Array
(
[ajax] => true
)
any idea why it doesnt detect the other variables ?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^page/([^/]+)/ /page.php?section=$1 [NC,QSA,L]
On my Wordpress blog, I used to have a plugin that I no longer need. The plugin used to create a bunch of URLs that looked like this:
http://tambnguyen.com/manage-subscriptions?srp=532&sra=s
with the postID being 532. How do I redirect the query strings so that the above URL will redirected to:
http://tambnguyen.com/?p=532
I've tried a few method without any luck (there's an optional "/" after "manage-subscriptions"
<IfModule mod_rewrite.c>
RedirectMatch 301 ^/manage-subscriptions/?\?srp=(\d{1,5})(.*)$ http://tambnguyen.com/\?p=$1
</IfModule>
Please help. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^srp=([^&]+) [NC]
RewriteRule ^manage-subscriptions/?$ /?p=%1 [L,R=301,NC]
I want to
redirect /directsystems/education/index/name/system_one
TO
http://www.mysite.com/directsystems/education/index/name/system-one
Can you please show me the 301 redirect rule for htaccess? As i want to redirect undescores with hypens
To replace all underscores _ with hyphen - in URI, use following rules in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^([^\_]+)_([^\_]+)(_.*)$ /$1-$2$3 [N,DPI]
RewriteRule ^([^\_]+)_(.*)$ /$1-$2 [L,R=301,DPI]
This redirects a URL of:
http://localhost/directsystems/education/index/my_name/system_one
to
http://localhost//directsystems/education/index/my-name/system-one
Try this:
RewriteRule ^([^_]*)_([^_]*)$ $1-$2