rewriterule on regular expression, htaccess - .htaccess

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.

Related

how to rewrite multiple and single params in url

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).

Im trying to combine three various clean url rules

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]

.htaccess simple rewrite not working

For some reason this isn't working, am I missing something obvious?
RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
I guess you need to exclude your target file from the RewriteRule because this may cause an infinite loop of rewrites:
RewriteRule ^acatalog/infopopup.html - [L]
RewriteRule ^(.*)infopopup.html$ acatalog/infopopup.html [L]
It was a looping issue, here's what ended up working:
RewriteBase /
RewriteCond %{REQUEST_URI} !/acatalog/.*
RewriteRule ^(.*)infopopup.html$ acatalog/infopopup.html [QSA,L]

htaccess two parameter mod-rewrite problems

I'm trying to setup a more friendly URL system and failing miserably. I want to be able to pass 1 or 2 GET parameters like this:
http://website.com/1234/123456
where 1234 is the first param and 123456 is the second param.
In my attempts Apache keeps viewing the /1234/ as a folder and a parameter. Here's what I've tried so far:
RewriteRule ^([^/]*)/([^/]*)$ index.php?id=$1&pa=$2 [L]
and
RewriteRule ^(.*)/(.*)$ index.php?id=$1&pa=$2
RewriteRule ^(.*)$ index.php?id=$1 [L]
You could do it like this:
RewriteEngine On
RewriteRule ^/?index\.php$ - [L]
RewriteRule ^/?(?:([^/]*)(?:/([^/]*)/?)?)?$ /index.php?id=$1&pa=$2 [L]
It's a little strict and messy, so you could just try:
RewriteEngine On
RewriteRule ^/?index\.php$ - [L]
RewriteRule ^/?(([^/]*)(/?(.*)))?$ /index.php?id=$2&pa=$4 [L]
That will take everything past the last so host.com/123/1233/56 will rewrite to host.com/index.php?id=123&pa=1233/56 while the first won't rewrite it, because of the 56

Joomla .htaccess problem

I am trying to rewrite from
mysite.com/pokerbono/xyz
to
mysite.com/pokerbono.php?id=XYZ
Here is the code I added in the .htaccess:
#### Affiliate Links
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
What is wrong with this rule? I tried like 100 variations and always receive a 404.
I tried each and every variation right now I have in my .htaccess the following rows:
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)/$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)/$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ /pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)/$ /pokerbono.php?id=$1 [L]
Try including slashes on the front:
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ /pokerbono.php?id=$1 [L]
UPD:
This works in my environment:
RewriteEngine On
RewriteRule ^qwe/([-_a-zA-Z0-9]*)$ qwe.php?id=$1 [L]
I had to disable Multiviews, now it is working fine :)

Resources