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

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.

Hi ryantroop

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

try using

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

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

thanks OsaMasw.

Not working

Member Avatar for diafol
RewriteEngine On
RewriteRule ^([^/]*)$ /article.php?url=$1 [L]

diafol,

I am getting 404 error.

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

Hi diafol

I updated as per the link. Not working.

Member Avatar for diafol

Sorry can't help. Anybody else?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.