Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite rule for subfolder (nice url)

I have trying to figure out how to get working in subfolder "admin" the same thing which works in root dir, problem is I don't know how to do that.

Currently I have:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]

# /
RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
RewriteRule ^(.+[^/])$ /$1/ [R=301]

Now it works like: http://example.com/page translate into http://example.com/?arg=page

What I would like to do in addition is this: http://example.com/admin/page translate into http://example.com/admin/?arg=page

I don't know at all how to make that happen, can somebody help me please?

Thanks

like image 723
user1085907 Avatar asked Mar 13 '23 02:03

user1085907


2 Answers

You can use these rules with appropriate RewriteBase:

RewriteEngine On
RewriteBase /admin/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]
like image 109
anubhava Avatar answered Mar 31 '23 11:03

anubhava


Or just add

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin/(.*)$ admin/index.php?arg=$1 [L,QSA]
like image 38
Muhammed Avatar answered Mar 31 '23 12:03

Muhammed