i am new to URL Rewrite. i want to rewrite my URL like given below.
www.mywebsite.com/q/1st-parameter/2nd-parameter
to
www.mywebsite/1st-parameter/index.php?q=2nd-parameter
Please note that the 1st-parameter/2nd-parameter is a string and it also contain "-". the Rule which i used in .htaccess file is
RewriteEngine On
RewriteRule ^.+/q/([a-z,A-Z,0-9]+)/([a-z,A-Z,0-9]+) /$1/index.php?q=$2 [NC,L,R]
Your quick reply will be highly appreciated. kindly also look at the Flags, whether i am using the correct flags or not. infact i copied it from a forum but failed to get the correct results.
Thanks in Advance
Related
I want to rewrite an URL such as: mysite.com/Section/Subsection/SubSubSection into
mysite.com/index.php?s=Section&sub1=SubSection&sub2=SubSubSection
I wrote this rule:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ /index.php?s=$1&sub1=$2&sub2=$3
But the problem is that Section, SubSection and SubSubSection are not mandatory at all, but if I insert some '?' character it goes on Internal Server Error...
(I tried this:
RewriteRule ^([^/]*)(/([^/]*))?(/([^/]*))?/?$ /index.php?s=$1&sub1=$3&sub2=$5
but it doesn't work)
Another problem is that there are other URLs that should not be edited, such as /res/img/logo.png.
The site in question is dynamic, so I don't know the section names beforehand. I know URLs that should be excluded, of course.
Any solutions? Thanks in advance.
I think you should do something like that ...
RewriteRule ^/([a-zA-Z]*)/([a-zA-Z]*)/([a-zA-Z]*)/?$ /index.php?s=$1&sub1=$2&sub2=$3
regards,
Mimiz
I've seen many cases of these rewrite questions but I don't get all the regular experessions and browser errors and such so I was hoping that someone could help me.
Ok, so I have a file with a url variable 'pages.php?p=foo' and I would like to rewrite it so that it appears as 'foo.html' in the same directory.
I was thinking along the lines of:
RewriteRule (.+).html pages.php?p=$1
The trouble is, the browser displays 400 Bad Request errors.
I'm hoping there's a fix for this but I can't get my head around it.
Any help is much appreciated :)
Try this:
RewriteRule (.*)\.html pages.php?p=$1
for a site move I need to hardcode some very simple URL Rewrites. I only see examples with regular expressions but what I need is this:
I have a CSV like
new URL, old URL
http://shop.example.com/categoryB, http://example.com/shop/categoryC
as you see, as the category names are not the same, there is no Regex magic necessary, I just want to create a .htaccess file with one URL Rewrite per line, that's it.
I tried
RewriteRule http://shop.example.com/categoryB http://example.com/shop/categoryC [L,R=301]
but this doesn't seem to work,
thanks for the help!
Have you turned on the ReWrite engine at the start of your htaccess file?
I would guess at something like this:
RewriteEngine On
RedirectMatch 301 http://shop.example.com/categoryB http://example.com/shop/categoryC
Ok, the answer looks like this:
RedirectMatch 301 /categoryOLDSITE http://example.com/shop/categoryNEWSITE
important is the slash in front of the old site and that it isn't a complete URL but a relative one to the location of the .htaccess file.
further information here: http://httpd.apache.org/docs/2.0/mod/mod_alias.html
I'm not sure whether this is the origin of the bug I'm trying to solve, however, I'm still not sure I correctly understood Apache doc...
Let's say I wanna redirect
toto.page?a=2&c=546EUE&stuff=blah
to
index.page?view=Blahblah/Toto&a=2&c=546EUE&stuff=blah
Of course, if there was other parameters, they should be preserved too.
Is the following rule correct?
RewriteRule ^toto\.page$ index.page?view=Blahblah/Toto [NC,QSA,L]
Yes. That is correct.
I'm currently working on an overhaul of my blog site, and have found a way to convert all my current pages into static html pages. They are currently using friendly url's which remap to a central index.php page with GET parameters attached on.
The change I am trying to make is have those same friendly URL's map to their html counterparts. I am currently using this rule:
RewriteRule ^archives?/([^/]+)/([^/.]+)/?$ archives/$1/$2.html
The error log is reporting that it cant find blah.html/ which means it's looking for the .html directory, instead of the .html file. So a better example:
/archives/2009/original-name
should be getting mapped to
/archives/2009/original-name.html
but is really getting mapped to
/archives/2009/original-name.html/
What am I missing here?
don't you need to use it the other way around? I didn't test the code but it should be something like this:
RewriteRule ^archives/(.*)/(.*).html archives/$1/$2
I can't see anything obviously wrong with your regex.
At a guess I'd say you might have a rule somewhere following this, which is redirecting anything without a trailing slash to its equivalent with the slash (a common thing to do to avoid duplicate content issues).
You didn't escape your period in the 2nd statement. Try this.
RewriteRule ^archives?/([^/]+)/([^/\.]+)/?$ archives/$1/$2.html