Mitchell Layzell
Mitchell Layzell

Reputation: 3058

Apache mod rewrite for dynamic pages

I'm having a problem with my mod rewrite rule that I wrote for my website, nothing seems to change as my pages URL are loading the same as before, if anyone could have a look at it and let me know if there is any problems it would be very much appreciated, thanks!

REWRITE RULE

RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?art_id=$1 [L]

URL

http://www.test.com/index.php?art_slug=test

DESIRED RESULT

http://www.test.com/test

Upvotes: 3

Views: 651

Answers (3)

Rakesh Dongarwar
Rakesh Dongarwar

Reputation: 529

RewriteEngine On
RewriteRule (.*)/$ search.php?keyword=$1

Should work. :)

Upvotes: 0

anubhava
anubhava

Reputation: 784968

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# to externally redirect from /index.php?art_slug=test to /art_slug/test
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+/(?:index\.php|)\?([^=]+)=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

# to internally forward from /art_slug/test to /index.php?art_slug=test
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/(.+)$ /index.php?$1=$2 [L,QSA]

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

Upvotes: 2

user2019515
user2019515

Reputation: 4503

RewriteEngine On 
RewriteBase / 
RewriteRule ^(.*)$ index.php?art_id=$1 [L]

Should work. :)

Upvotes: 0

Related Questions