wawan Setiyawan
wawan Setiyawan

Reputation: 371

htaccess make dynamic url to static url

I have a URL like:

http://localhost/admin-s/index.php?m=user

However, I would like a URL like this:

http://localhost/admin-s/user

I try like this:

RewriteRule ^([a-z0-9]+).php$ index.php?nol&m=$1 [L]
RewriteCond %{QUERY_STRING} ^m=([a-zA-Z0-9]+)$
RewriteRule ^index.php$ user%1.php [L]

How to make it?

Upvotes: 1

Views: 133

Answers (4)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try below in your admin-s direcotry,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ index.php?m=$1 [L]

Upvotes: 1

Sahil Gulati
Sahil Gulati

Reputation: 15141

Hope this simple configuration will help you out. You can check this configuration here

This will redirect request of this pattern from http://localhost/admin-s/index.php?m=user to http://localhost/admin-s/user

Explanation:

1. If REQUEST_URI is /admin-s/index.php

2. If QUERY_STRING is m=someWords

3. Redirect to /admin-s/someWords

.htaccess

RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_URI} \/admin\-s\/index\.php
RewriteCond %{QUERY_STRING} m=([\w]+)
RewriteRule ^(.*)$ /admin-s/%1? [R=301,L]

Upvotes: 2

Amit Verma
Amit Verma

Reputation: 41219

You can use the following rule in your root/.htaccess or /admin-s/.htaccess :

RewriteEngine on

#redirect /admin-s/index.php?m=user to /admin-s/user
RewriteCond %{THE_REQUEST} /admin-s/index\.php\?m=([^\s&]+) [NC]
RewriteRule ^ /admin-s/%1? [L,R]
#rewrite the new uri back to the orignal location
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:admin-s/)?(.+)$ /admin-s/index.php?m=$1 [NC,L]

Upvotes: 1

Shajibur Rahman
Shajibur Rahman

Reputation: 466

The question was answered here : How to turn dynamic URL into static URL

For your problem may be try following rules:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^admin-s/([^-]+) /index.php?m=$1 [R=301,QSA,L]

Let us know if it works

Upvotes: 1

Related Questions