0

Hi friends

i am facing some url redirection issue in my .htaccess. please help me to fix it.

my url is

domainname.com/article.php?url=test.html

my expected URL is

domainname.com/test.html

.htaccess

Options +FollowSymlinks
RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1

Server nginx

4
Contributors
10
Replies
41
Views
2 Years
Discussion Span
Last Post by ryantroop
0

I believe you are missing your leading slash..
RewriteRule ^/([a-zA-Z0-9-/]+).html$ /article.php?url=$1

Also remember, do MOST specific to LEAST specific. So, your order is incorrect.

You also seem to be missing some flags that will terminate the rewrite, and you possibly have yourself stuck in a loop so apache ignores the rule.

For more info, please see:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags

I do recall that a few companies (godaddy) also require a few XML type markups to your .htaccess file to work as expected. You may want to look into your hosts idea of a "properly formatted" .htaccess file for mod_rewrite.

0

Hi ryantroop

Thanks for your reply. i tried what you suggested but its not working.

0

try using

RewriteRule ^(.*).html$ article.php?url=$1

for testing only and see if its working
and remove double rules for same thing.

0

diafol,

I am getting 404 error.

i am getting the URL as domainname/article.php?url=article.php

Edited by rpv_sen: updated

0

try:

Options +FollowSymLinks -Indexes -Multiviews

<IfModule mod_rewrite.c>

    SetEnv HTTP_MOD_REWRITE On
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*).html$ /article.php?url=$1 [NC,L]

</IfModule>

basically
set a few options (including the all important +FollowSymLinks)

if mod_rewrite exists
Enable it
set the base to /
make sure we dont ever rewrite direct requests for images, css, or js files
or any files
or a proper directory
and then rewite our url pattern.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.