I have a url like this
http://be.ac/index.php?category=all&providers=all&keyword=cookies&page=1
I want to rewrite like this:
http://be.ac/category/all/providers/all/keyword:cookies/page:1
this is my htaccess
RewriteEngine on
RewriteRule ^page:([^/]*)/?$ index.php?page=$1 [QSA,L]
RewriteRule ^category/([^/]*)/?$ index.php?category=$1 [QSA,L]
RewriteRule ^category/([^/]*)/page:([^/]*)/? index.php?category=$1&page=$2 [QSA,L]
RewriteRule ^category/([^/]*)/providers/([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&page=$3 [QSA,L]
RewriteRule ^category/([^/]*)/providers/([^/]*)/keyword:([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L]
this is not working, what I need is accept urls like this:
http://be.ac/category/all/providers/all/keyword:cookies/page:1
http://be.ac/category/all/providers/all/page:1
http://be.ac/category/all/page:1
http://be.ac/page:1
http://be.ac/keyword:cookies
any ideas?
I believe the issue is with regards to colons. First guess is that they would need to be encoded, unless in a hash-string.
As such, you'd be getting a 403 Forbidden error thrown - though, you have not specified in your question.
The only thing I can recommend is switching out those colons for forward slashes, which keeps the URI consistent (like you have done with category/<something> instead of category:<something>):
RewriteEngine on
RewriteRule ^page/([^/]+)/?$ index.php?page=$1 [QSA,L]
RewriteRule ^category/([^/]+)/?$ index.php?category=$1 [QSA,L]
RewriteRule ^category/([^/]+)/page/([^/]+)/? index.php?category=$1&page=$2 [QSA,L]
RewriteRule ^category/([^/]+)/providers/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&page=$3 [QSA,L]
RewriteRule ^category/([^/]+)/providers/([^/]+)/keyword/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L]
Also, I've changed ([^/]*) to ([^/]+), and fixed the trailing slash issue with the last two issues (they were inconsistent with the others).
Related
I have similar URLs which I want to redirect but the issue is that the first URL overrides the others. For example
RewriteRule ^user/([a-zA-Z0-9-_]+) user.php?user=$1 [NC,L]
RewriteRule ^user/([a-zA-Z0-9-_]+)/about about_user.php?user=$1 [NC,L]
RewriteRule ^user/message/([a-zA-Z0-9-_]+) message_user.php?user=$1 [NC,L]
But the first RewriteRule overrides the others so if I have something like this
example.com/user/message/myName
example.com/user/myName/about
They are all redirected to user.php. Please am new to this, how can I get it fixed?
I believe you should have a $ sign after your regular expressions, so it becomes:
RewriteRule ^user/([a-zA-Z0-9-_]+)$ user.php?user=$1 [NC,L]
RewriteRule ^user/([a-zA-Z0-9-_]+)/about$ about_user.php?user=$1 [NC,L]
RewriteRule ^user/message/([a-zA-Z0-9-_]+)$ message_user.php?user=$1 [NC,L]
This isn't working,
RewriteEngine On
RewriteBase /
RewriteRule ^res/ - [L]
RewriteRule ^.*$ /server/entry.php?PAGENAME=$1 [QSA,L]
ErrorDocument 403 /notfound
ErrorDocument 404 /notfound
I think the last code is not working, I have tried to change ^.* -> (.*) but the result was the same.
I could be wrong, but this last line is the one with wrong statement, but I dont know what to do with it anymore. Tried all I could.
RewriteRule ^.*$ /server/entry.php?PAGENAME=$1 [QSA,L]
Been struggling on this for 2 days now... I have done research online and tried other codes but didn't work either.
This didnt work,
RewriteRule ^.*$ /server/entry.php?PAGENAME=$1 [QSA,L]
This worked,
RewriteRule ^.*$ server/entry.php?PAGENAME=$0 [QSA,L]
Probably the setting of the server, but I shouldnt use the absolute path.
my problem is that I want to get three simple rules working, but my knowledge is too little, to get them working together:
These are obvious:
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
domain.com/login and domain.com/register
Secondly, since i have only one page used for displaying data, i want its url to be as simple as posible, like:
RewriteRule ^(.*)$ /data.php?id=$1 [L]
which should be translated into:
domain.com/1a2s3d
As third, I want to be able to change url with activation code:
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
which finally should be translated into:
domain.com/register/activate/some-hash
I know just simply basics. And I cannot mix all of these three ideas into one single working htaccess file. With the second rule the server gives me 500 error, with third rule registration page works, but css file path is translated into domain.com/register/activate/theme/style.css instead of domain.com/theme/style.css
Any help would be appreciated.
Try just with that:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
RewriteRule ^(.*)$ /data.php?id=$1 [L]
I'd like to rewrite two things on one site.
mysite.com/something -> mystie.com/index.php?s=something
and
mysite.com/something/another -> mysite.com/index.php?s=something&d=another
This is my htaccess
RewriteEngine on
RewriteRule ^(.+)$ index.php?s=$1 [L,QSA]
RewriteRule ^(.+)/(.+)$ index.php?s=$1&d=$2 [L,QSA]
Separately both work but together they don't...
I'm guessing the problem is that you're matching the '/' character in your first rule. Wouldn't the easiest solution be to simply add a character class to your rules, like:
RewriteRule ^([a-z0-9]+)$ index.php?s=$1 [L,QSA]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$ index.php?s=$1&d=$2 [L,QSA]
or simply change the order of the rules:
RewriteRule ^(.+)/(.+)$ index.php?s=$1&d=$2 [L,QSA]
RewriteRule ^(.+)$ index.php?s=$1 [L,QSA]
Reverse the two rules. The rewrite engine goes through the file line by line, sequentially. The first rule you have:
RewriteRule ^(.+)$ index.php?s=$1 [L,QSA]
matches a url that has two name value pairs as well, so the file stop processing after the first match because you are using the L flag.
RewriteRule ^(.+)/(.+)$ index.php?s=$1&d=$2 [L,QSA]
RewriteRule ^(.+)$ index.php?s=$1 [L,QSA]
I don't have time to test this for you, sorry. But I'm feeling strongly that this is the problem. While I was writing this answer, someone gave pretty much the same advice. I thought of deleting my answer but want to make sure that you understood about the L flag and that the file is processed sequentially.
RewriteEngine on
RewriteRule ^([a-z0-9]+)$ index.php?s=$1 [L,QSA]
RewriteRule ^([A-Za-z0-9]+)/(.+)$ index.php?s=$1&d=$2 [L,QSA]
This works. Changing order didn't work. Also I forgot add that
mysite.com/something/another
the another string can be like asd-1231-ASDwqda .
I have the following rules in .htaccess. Unfortunately, it does not work due to the last rule (everything else works fine). Why?
Options -Indexes
RewriteEngine On
RewriteRule ^(cdn) - [L]
RewriteRule ^admin/(.*)$ backend_0.0.1/index.php/$1 [QSA,L]
RewriteRule ^css/(.*)$ frontend_0.0.1/css.php/$1 [NC,QSA,E=no-gzip:1,L]
RewriteRule ^js/(.*)$ frontend_0.0.1/js.php/$1 [NC,QSA,E=no-gzip:1,L]
RewriteRule ^(.*)$ frontend_0.0.1/index.php/$1 [QSA,L]
If I replace the last line by:
RewriteRule ^(.*)$ frontend_0.0.1/index.php?q=$1 [QSA,L]
Then it suddenly starts to work but previous rules are skipped and only this last rule is applied. But I need rules to stop rewriting once the first one mathches.
You need to exclude the destinations you are redirecting to:
RewriteCond $1 !^(backend_0\.0\.1|frontend_0\.0\.1)/
RewriteRule ^(.*)$ frontend_0.0.1/index.php/$1 [QSA,L]