i m new to .htaccess. I have many searches, nothing works well.
I wanted to convert my dynamic page to static.
test.com/?gender=pop&rows=1&page=2 to
test.com/gender/pop.html?rows=1&page=2
also work for
test.com/?gender=pop to
test.com/gender/pop.html
simply only rewrite first query. thanks
This should work:
RewriteEngine On
RewriteRule ^gender/(.+)\.html$ /\?gender=$1 [L,QSA]
PS: this will work with any gender. (EX: gender=pop, gender=male, gender=female, gender=123, ...) Please let me know if you need it to be more specific.
Why you like to keep dynamic parameters ?
Test something like this :
RewriteRule ^gender/([a-z]+)\.html\?rows\=([0-9]+)\&page\=([0-9]+)$ gender=$1&rows=$2&page=$3 [L]
I hoe this help,
Mike
Related
I have some problems with my URL rewriting.
I just want to change my URL paradigm's who is :
http://www.siteadress.com/index.php?//something/something to something like that :
http://www.siteadress.com/something/something
So I add this line :
RewriteRule (.?)index.php\?/(.*) /$1$2
But that does'nt work as I planned.
That just remove 1 / from my URL.
Yet in my meaning, I ask for (.?) anything optionnal index.php\?/ index.php?// (.*) and anything, no?
Thank you for your help.
It looks like you have the rule in reverse order. The first argument should be the pattern you're looking to match, the second argument being what you want to replace it to. In your case, you're looking for "/something/something" and wanting to rewrite that to "/index.php?//something/something". So you need something like:
RewriteRule ^/?(.*) /index.php?//$1
That will take anything after the first / in the path and append it to /index.php?//.
I know this has been asked a million times, but I can't figure it out . Please help.
This is the original URL:
http://booksnearby.in/show_post.php?title=some_words&id=99
Which I want it to appear as
http://booksnearby.in/show_post/some_words
How ?
I been at this for hours now , just can't figure this out.
Thanks
Try this rewrite rule
RewriteRule ^showpost/(.*)$ http://booksnearby.in/showpost.php?title=$1&id=99
This will rewrite http://booksnearby.in/showpost/titlesearch to http://booksnearby.in/showpost.php?title=titlesearch&id=99
I've hard coded the id above as clearly its impossible to have this rewritten based on the incoming URL.
How can I use mod_rewrite to take http://www.site.com/events?pg=4 and turn it to a clean URL, like so: http://www.site.com/events/4 ?
Thanks for the help!
Something like this should do the job:
RewriteEngine On
RewriteRule ^events/([^/]*)$ /events?pg=$1 [L]
What it's doing is:
Turning on the Rewrite engine
Matching any request that has the form events/something
Storing the 'something' (the brackets indicate that the match should be stored)
Redirecting to the ugly form using the stored variable.
Preventing any further rules from being applied ([L])
Hope this helps.
I have a problem with rewrite rule
my link
is www.something/group/group_id/place/groupName
for this
rewriteBase /
RewriteRule ^group/(.*)/(.*)/(.*)$ /group.php?gid=$1 [QSA,NC,L]
somet times my url may come www.something/group/group_id/groupName.
In Both cases I have to rewrite to group.php and I need only groupid. How to write rewrite rule to work in both situation?
Either use lazy quantifiers or prevent each matching group from matching the / itself. The way you have it currently, the first group will match as much as it can resulting in unwanted results.
RewriteRule ^group/(.*?)/(.*?)/(.*?)$ /group.php?gid=$1 [QSA,NC,L]
RewriteRule ^group/([^\/]*)/([^\/]*)/([^\/]*)$ /group.php?gid=$1 [QSA,NC,L]
An even better way, to allow people to leave out unnecessary parts (read: not needed to evaluate the result on the server side), you could even do something like this:
RewriteRule ^group/(\d+)(/.*)?$ /group.php?gid=$1 [QSA,NC,L]
(This is based on the assumption that your group id is a number)
Try this one:
^group/(.+)(/|/.+)*$
It matches for
www.something/group/group_id/place/groupName
www.something/group/group_id/groupName
I never used the RewriteRule, so it's not tested. And maybe if you add the "Regex" Tag to your question you'll get more answers ;-)
how do I configure my .htaccess rewrite rules to accomodate GET requests?
Currently, /manager/page goes to: ?dept=manager&n=page however, some pages have additional GET reqs, and so this rule doesn't work:
RewriteRule ^([A-Za-z]+)/([A-Za-z]+)$ index.php?dept=$1&n=$2 [QSA]
I would need: ?dept=manager&n=page&id&etc=etc to go to: /manager/page/id/5/etc/6 however, not all pages present the same method of id input, IE. some pages used id, others catid, and others, bugid, so it's a bit difficult.
Thanks :)
UPDATED: END URL - id/5/etc/6
You just need to sepcify a different rule.
RewriteCond ${HTTP_METHOD} "GET"
RewriteRule --your rule--
If your input methods are really that varied, you should use multiple RewriteRules for each different format.