I want to change the URL of my website using .htaccess file :
http://godofindia.com/Guru+Saint+Mahatma-103/
to
http://godofindia.com/Guru-Saint-Mahatma-103/
I only want the + sign to be replaced by - sign
please help
I don’t think that this is possible using plain .htaccess. If you really need to change your URLs, I would use a small script (i.e. PHP) that handles the replacment:
<?php
$uri = $_SERVER['REQUEST_URI'];
$new_uri = str_replace('+', '-', $uri);
header('Location: ' . $new_uri);
And then, rewrite Requests to that script using a RewriteRule:
RewriteEngine On
RewriteRule ^.*+.*$ rewrite-plus.php
I have found same issue, so i am using "%20" instead of "+" sign.
You can check it out that will work in most of all cases. In many site also if you write "test+play" or "test%20play" both work same
May this will help you
try:
RedirectMatch 301 ^/(.*)\%2[Cc]$ /$1-$2
Related
I need to write 301 redirection code in htaccess.
What I have tried.
RewriteRule ^old-url-shoes/$ new-url-shoes-abc/#div-id-shoes [R=301,NC,L]
This code is creating this url
new-url-shoes-abc/%23div-id-shoes
It is replacing '#' with '%23'.
Please suggest a solution.
Could you please try following once, written and tested with shown samples.
Please do clear your browser cache before testing your URLs.
RewriteRule ^old-url-shoes/$ new-url-shoes-abc/#div-id-shoes [R=301,NC,NE,L]
From documentation:
NE|noescape By default, special characters, such as & and ?, for
example, will be converted to their hexcode equivalent. Using the [NE]
flag prevents that from happening.
Also as an additional suggestion use ^old-url-shoes/?$ ? so it will cover cases of either url is ending with slash or not in Rules.
Everyone who have tried to search through error_log files from large websites got lots of links like these bellow due to people who have screwd up some html in third part sites or blogs...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html'http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html/mydomain...
The problem is some extra chars after the .html...
Its easy to guess the correct url in each case... we just have to truncate the url after the ".html".
Is it possible with .htaccess to rewrite these problematic urls to the correct syntax?
Just eliminating everything after the .
html? And avoiding messing up with url queries in dynamic urls?
Here's what I would like to do ...
Replace ".html " with ".html#"
Replace ".html'" with ".html#"
Replace ".html/" with ".html#"
As everything after the # will be just ignored...
Any simple way to do that with .htaccess?
Just use a Regex:
RewriteRule ^(.*)\.html(.*)$ $1.html
This RedirectMatch rule should work:
RedirectMatch 301 ^(.+?\.html).+$ $1
I need to redirect a page like this (values could change in query string)
http://www.domain.com/list.php?id=bla&variable2=product1-product2-product3
Redirect to
http://www.domain.com/list.html?id=bla&variable2=product1-product2-product3
All i need is it to change to .html but everything else should remain the same on the bespoke links.
Any help out there?
Is it a bad idea to do the redirection in list.php file instead of using an .htaccess file?
How about something like:
header('Location: http://www.domain.com/list.html?'+$querystring);
in list.php?
Put this in you htaccess, it should be enough.
RewriteRule ^([^.]+).html$ /$1.php [QSA,L]
(And by the way, it's useless to do this...)
I have got a problem that seems to me something simple but i'm new to htaccess and can't find the solution.
i've got the following line in my htaccess (root map)
RewriteRule ^page1/([a-zA-Z0-9_-]+)/$ page1.php?name=$1
RewriteRule ^page1/([a-zA-Z0-9_-]+)$ page1.php?name=$1
When i enter the the following url it works without a problem
www.myexample.com/page1/variable
the strange thing happens when I add a / at the end. Then the page can't get the GET value out of the URL.
Thanks for your time and help!
Get rid of the ending /$ sign on the first rule
RewriteRule ^page1/([a-zA-Z0-9_-]+) page1.php?name=$1
Or you can continue to capture data
RewriteRule ^page1/([a-zA-Z0-9_-]+)/(.*)$ page1.php?name=$1
Ultimately if you want to keep capturing more data with "/" as a delimiter, I suggest doing
RewriteRule ^page1/(.*)$ page1.php?url=$1
Then use the server side script to determine what to do.
I have a url with the format http://www.site.com/index.php/page and want to rewrite it to http://www.site.com/#/page but I can't seem to find an answer anywhere. Can anyone help?
If you simply want to replace index.php with # you can do something like this:
RewriteRule ^/index.php/(.*) /#/$1 [NE,R]
The NE flag should keep mod_rewrite from escaping the #