I am using url rewrite like this
RewriteRule ^help$ help.php
so if user come with domain.com/help it work
but if user call page like domain.com/help/ it send err 404 page not found
how can fix this that in 2 case it do same job
Try this rule:
RewriteRule ^help/?$ help`
Adding /? makes the trailing-slash to be optional. The pattern then starts to match help as well as help/
You can test this rule here
You need to make the trailing slash in your regular expression optional:
RewriteRule ^help/?$ help.php
Related
I need to redirect an incoming request with the following URL:
http://mywebsite.com/abc/mapserv.exe?map=123
to
http://mywebsite.com/abc/mapserv.exe?map=C:\Mapserver\ms4w\Apache\htdocs\Mapfiles\123.map
I already managed to do simple mod_rewrites but the question mark is killing this one all the time. I am not able to adapt common Query String examples to my case so I need help with this exact case.
As though you did not show your try, you could test this:
RewriteEngine On
RewriteCond %{QUERY_STRING} map=([0-9]+)$
RewriteRule . %{REQUEST_URI}?map=C:\\Mapserver\\ms4w\\Apache\\htdocs\\Mapfiles\\%1.map [NE,L]
Rewrite flags used:
NE: Not Escape,
L: Last instruction to run.
I was still having trouble with the .exe url since it is not accessible if you dont deliver the parameters right when you send the request. And then the redirect wont fire. So I made a dummy mapserver.php file which allows setting a parameter like so:
http://mywebsite.com/abc/mapserver.php?map=123
After hours of trying I ended up with the following RewriteRule:
RewriteCond %{QUERY_STRING} ^map=(.*)$
RewriteRule ^mapserver.php?$ /cgi-bin/mapserv.exe?map=C://Mapserver//ms4w//Apache//htdocs//Mapfiles//%1.map
I can access url without extension i.e I can access
'www.example.com/signUp/save' and 'https://www.example.com/signUp/save'
Now I am trying to redirect the following:
'www.example.com/signUp/save.php' to 'https://www.example.com/signUp/save.php'
'www.example.com/signUp/save' to 'https://www.example.com/signUp/save'
using this rule:
RewriteRule ^signUp/(.*)$ https://%{HTTP_HOST}/signUp/$1
I am able to rewrite the first one but not the second. Also after writing this rewrite rule in my .htaccess file I get 'Not found' for 'www.example.com/signUp/save'
What is the correct way of doing this?
Try this:
RewriteRule ^signUp/([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)?$ https://%{HTTP_HOST}/signUp/$1
I need to add ?lang=English to an url /self-service/more here if a visitor comes from a specific domain. (not comes from, thats impossible but i meant was first at site A and then clicked a link and went to my site)
How can i do that? I tried reading the manual but its actually a bit over my head
Try using the mix of rewrite condition and rewrite rule like this, placed on top of .htaccess
RewriteCond %{HTTP_REFERER} ^(http|https)://best-graphic-design\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1?lang=English [R=301,L,QSA]
A simple explanation
First check for the referer to your site, NC flag stands for nocase/ignore case
If condition matches, redirect to desired location, in your case, same host while appending the new parameter, flags used here are R - Redirect, L - Last, QSA - Query String Append.
Hope it finally helps.
I'm trying to get the following URLs be case insensitive and to go to same spot:
http://www.mywebsite.com/test
http://www.mywebsite.com/TEST
I have the following rule:
RewriteRule ^/([a-zA-Z0-9_\-]+)/?$ /?param=$1 [L]
It works for lowercase but when I have 'TEST' after website name, it doesn't apply.
I get The requested URL /TEST.php was not found on this server. Appending .php is another URL rule that comes after the rule above. So it looks like, it doesn't match the rule and goes on to next.
Try the following:
RewriteRule ^([a-zA-Z0-9_\-]+)?$ /index.php?param=$1
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ /index.php?param=$1
Explicitly referring to the index file makes it clearer. The second rule should be added if you want to match trailing slashes on your 'test' param.
This works with both http://www.mywebsite.com/test and http://www.mywebsite.com/TEST
I have a few URLs that are now 404ing due to products expiring, and I need to redirect them to a related page that does exist.
e.g.
http://www.example.com/package-product.php?id=72 to http://www.example.com/best-sellers/
http://www.example.com/package-product.php?id=36 to http://www.example.com/bedroom-furniture/
etc.
As I understand it, I can't do this with a Redirect 301 because of the GET param, and the examples I've seen for rewrite seem to be a bit more generic and use a placeholder for the params - I need to send a specific URL to a specific alternative.
Thanks.
I'd probably do it the way #BobLiu suggested - i.e. to do it in PHP itself.
If that's not possible if you really want a rewrite solution, you can look at the QUERY_STRING variable available to mod_rewrite:
RewriteCond %{QUERY_STRING} id=72$
RewriteRule ^.*$ http://www.example.com/best-sellers/ [R=301,L]
Why not just say on the package-product.php page something like:
switch ($_GET['id'])
{
case 72:
[do redirect url1];
case 36:
[do redirect url2];
etc...etc..
}