I have this rule:
RewriteRule ^([a-z\-]*)/([a-z\-]*)/?([\w\d\=\:\,_-]*)?/?([a-z0-9\-]*)?/?$ $1.php?act=$2&cat=$3&sub=$4 [QSA,L]
It works with many URLs:
users/manage/
system/payments/
system/payments/n=20:o=paid_time:s=DESC
stores/themes/
stores/theme/n=20:o=created_time:s=DESC
But failed with this URL:
stores/themes/n=20:o=created_time:s=DESC
It's wrong with 1 addition 's' only.
Please help me with this, many thanks
Related
Firstly thanks for the support and sorry but I am new to RewriteRule.
I have the following url:
https://www.example.com/jobs/?job_title=&specialisms=&location=&radius=200&cs_=&cs_=Find+Job
which I want to make into :
https://www.example.com/(job_title)-jobs/in-(specialisms)/in-(location)
any help would be great.
until now I have always used htaccess to rewrite URLS in order to have non-SEF url to SEF urls.
Today I am facing a new challenge that honestly, beeing non confident in regular expression, I really don't know how to achieve.
I have a situation where a forum on a website of mine has been update in the following form:
previous link: www.domain.com/forum3/topic/name-of-topic/post/7548
new link: forum.domain.com/Topic-name-of-topic/
How do I intercept /post/37764 string and tell htaccess to not consider it?
And how to instruct the server to build that kind of url instead of the provious. I am very confused about it.
Any suggestion? Thank you very much. Is there any resource that I can read to help me better understand the case?
Thanks again.
EDIT
Florian answer is correct. I just added few mods to fit it better.
RewriteEngine On
#RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
RewriteRule ^forum3/topic/([^/]+)-[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
You can try this code :
RewriteEngine On
RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ /Topic-$1/ [L,R=301]
/([^/]+)/ means that we want to catch a string containing one or more characters except / preceded and followed by a /.
This link might help you to test your .htaccess files :
Test your apache htaccess files online
I need help with a URL problem I've encountered with a rewriteRule.
What I need it to do is following: example.com/en/page/page/
At the moment the following works fine: example.com/en/page/
But once it goes like "example.com/en/page/page/" I receive a 404 - page not found error even if the page in fact is located in the serverfiles.
The clue here is that I use a variable in the /en/ part of the URL (multilanguage system) and it seems that I cannot figure out how to get it to work with that included.
At the moment I have the following rewriteRule in my .htaccess file.
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?lang=$1&uri=$2 [L]
Do any of you have a clue on what might work?
Best regards,
PureDarkness
You don't include anything behind the second /. You could try:
RewriteRule ^([^/]*)/(.*)$ index.php?lang=$1&uri=$2 [L]
And you can add [QSA] if you also need to get the parameters.
I have the following URL: http://sitename.com/?parameter_1=data¶meter_2=data
it always remains the same with the same data. I want it to be converted into the following URL: http://sitename.com/most-popular
I believe it is quite simple to do it from .htaccess but I am not familiar with rewrite rules.
Thank you.
If I correctly understand what you mean, you could try this
RewriteRule ^most-popular/?$ ?parameter_1=data¶meter_2=data [L]
RewriteRule ^groups/([0-9+]*)/(.*)$ /users.php?group=$1 [QSA,L,E]
www.mysite.com/groups/11/all-users
in users.php i try get group id:
echo $_GET['group'];
Why always get "false"?
Thanks
I heartily recommend using the RewriteLog functionality for debugging your rewrite rules, I find it helps immensely to demystify what's happening inside.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
From what I can tell, you're merely missing the leading slash in the URL. I tested locally using (note the added leading slash before groups):
RewriteRule ^/groups/([0-9+]*)/(.*)$ /users.php?group=$1 [QSA,L,E]
The resulting page does a vardump of $_GET, providing:
array(1) { ["group"]=> string(2) "11" }
Try with this:
Example:
The original URL: http://www.mysite.com/users.php?group=1
The rewritten URL: http://www.mysite.com/group/1
RewriteEngine On
RewriteRule ^group/([^/]*)$ /users.php?group=$1 [L]