.htaccess: Rewrite Problem - .htaccess

I'm creating a website. I have this code in the .htaccess file:
RewriteEngine On
RewriteRule ^/([-a-zA-Z0-9_]+)/$ /redirect.php?id=$1
But when I go to, for example /ASEi it says 404 Not Found. What's the problem?

Try this instead:
RewriteRule ^/([-a-zA-Z0-9_]+)/$ /redirect.php?id=$1

I found it, the problem was the first /. The .htaccess now looks like: RewriteEngine On
RewriteRule ^([-a-zA-Z0-9_]+)$ redirect.php?id=$1

Related

What is wrong htaccess

I have the following htaccess rules but I dont know how to make it work:
RewriteEngine on
RewriteRule ^game/([^/]*)$ index.php?cash=$1
The following is the screen shot of my folders structure:
Can someone tell me how to get it to work? I have also tried:
RewriteRule ^index.php([^/]*)$ index.php?cash=$1
The URL that I want to display is: http://localhost/biteep/game/100 while the URL that I want the browser to go to is http://localhost/biteep/game?cash=100
Try to put a rewrite base into your .htaccess:
RewriteBase /biteep/
And this route should be enough:
RewriteRule ^game\/(\d+)$ index.php?cash=$1
So it works when I do this
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?cash=$1

Mod Rewrite .htaccess folder

I'd like to rewrite my parameter from www.example.com/admin/account?account=activity-log to www.example.com/admin/account/activity-log and I don't know how to do that properly. Here's my current .htaccess code:
RewriteEngine on
RewriteRule ^account/([^/]*)$ /admin/account.php?account=$1 [L]
That works well but that only gives me like this www.example.com/account/activity-log. I want to include the folder named admin/. I tried to add the admin folder before the account/ like this:
RewriteEngine on
RewriteRule ^admin/account/([^/]*)$ /admin/account.php?account=$1 [L]
but that only gives me 500 internal server error, please help.
Assuming your code is in: [doc_root]/admin/.htaccess, then probably best to declare a rewritebase. Try this:
RewriteEngine On
RewriteBase /admin/
RewriteRule ^account/([^/]+)$ account.php?account=$1 [L]

.htaccess change the URL page with three conditions

I want to change the url of my page like
http://localhost/Dynobase/my_computer.php?name=Deny-computer&type=computer&select=1
to
http://localhost/Dynobase/Deny-computer/computer/data/1
and to my htaccess file code like this
RewriteRule ^([a-zA-Z_-]+)/([a-zA-Z_-]+)/data/([[0-9]]+)$ /my_computer.php?name=$1&type=$2&select=$3 [L,NC]
but that I could actually error 404
maybe there is something wrong in my code.
please help me.
Thank you
Try this in /Dynobase/.htaccess:
RewriteEngine On
RewriteBase /Dynobase/
RewriteRule ^([\w-]+)/([\w-]+)/data/([0-9]+)/?$ my_computer.php?name=$1&type=$2&select=$3 [L,NC,QSA]

.htaccess rewrite with GET param

Im trying to transfrom link like this:
http://localhost/photohosting/user/view.php?img=60
Into something like that in users browser:
http://localhost/photohosting/60
Here my code for .htacces
RewriteEngine on
RewriteRule ^view.php(.*)$ /photohosting/user/view.php?img=$1 [L,QSA]
I'm not familiar with .htaccess so I can't found the mistake. Why this code doesn't work?
UPDATE: I've updated my .htaccess to:
RewriteRule ^([a-zA-Z0-9_-]+)$ user/view.php?img=$1 and now link like http://localhost/photohosting/60 works, but it misses param.
Try with the following rule:
RewriteRule photohosting/([0-9]+)$ /photohosting/user/view.php?img=$1 [L,QSA]

localhost htaccess url rewrite problem

I have already configured my apache(mod_rewrite,alias,allowOverride), and I am trying to rewrite
http://localhost/b33m/view_blog_details.php?post_id=4
To
http://localhost/b33m/blogs/4
so that user can simply type in the second url and it would work. But I am getting a 404 not found error.
I am using WAMP on XP, and my .htaccess is in www->b33m
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^b33m/blogs/([^/]*)$ /b33m/view_blog_details.php?post_id=$1 [L]
Try:
RewriteEngine On
RewriteRule ^blogs/(\d+)$ view_blog_details.php?post_id=$1 [L]
Note the / in the beginning of each URL have been omitted.
Try the following:
EDIT: I updated the code which hopefully will work better
RewriteEngine On
RewriteBase /b33m
RewriteRule ^blogs/([0-9]+)$ /view_blog_details.php?post_id=$1 [L]
Since you expect an id I'd rather use:
Moreover shouldn't you put a trailing slash?
RewriteEngine On
RewriteRule ^/b33m/blogs/(\d+)$ /b33m/view_blog_details.php?post_id=$1 [L]
Try adding this in your hosts file:
www.localhost.com 127.0.0.1
.htaccess sometimes doesn't like localhost

Resources