Mod Rewrite .htaccess folder - .htaccess

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]

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

Too many redirects using .htaccess file to cut and change URL

I've go a .htaccess file on my server with this code:
RewriteEngine on
RewriteRule ^([a-z0-9-]+)? index.php?i=$1 [L]
When I run this I've got something like this:
http://example.com/index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.phpi=index.php?i=XYZ
How to get link look like this:
http://example.com/index.php?i=XYZ
from link look like this
http://example.oom/XYZ/ABC/123
I only need first XYZ to index.php?i=XYZ
Working code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/.]+)?$ index.php?i=$1 [L]
</IfModule>

Rewrite URL to get contents from sub-directory

I have edited my /etc/hosts file to link domain.com to my localhost. Now when I visited domain.com I want it to get the site contents from domain.com/site/ but only using the URL domain.com thus removing site/ from the URL.
I have done this once before, so I know it's possible, but I lost the code. Can someone please assist me? .htaccess scripting is not my strong. Apologies if this is a duplicate of something else.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!site/).*)$ site/$1 [L,NC]
I have managed to get this working with the following code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)your_directory
RewriteRule ^(.*)$ your_directory/$1 [L]

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

.htaccess: Rewrite Problem

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

Resources