Engr Saddam Zardari
Engr Saddam Zardari

Reputation: 1049

how to write htaccess file, to change URL

i am trying to convert the actual URL to user friendly there is dynamic menu, when user click on page the orignal url becomes

http://example.com/single.php?name=mypagename

i want to change it to

http://example.com/page/mypagename

here is my htaccess file i tried from different angles Please can any one help to correct it..

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /single\.php(\?|\ )
RewriteCond %{QUERY_STRING} name=(.+)
RewriteRule page/(.*) single.php?name=$1
RewriteRule ^ /page/%1? [L,R=301]

Upvotes: 4

Views: 131

Answers (3)

anubhava
anubhava

Reputation: 785098

You must rearrange your directives:

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+single\.php\?name=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [L,R=301]

RewriteRule ^page/(.*)$ single.php?name=$1 [L,NC,QSA]

RewriteCond %{THE_REQUEST} \s/+(Web/2015/wessexcars)/internalpage\.php?seo=\?name=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [L,R=301]

RewriteRule ^(Web/2015/wessexcars)/(.+?)/?$ $1/internalpage.php?seo=$1 [L,NC,QSA]

Upvotes: 1

Ambarish Yadav
Ambarish Yadav

Reputation: 412

firstly change your config file make index file blank

$config['index_page'] = '';

and make a htaccess file

    <ifmodule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </ifmodule>

Upvotes: 0

rdanusha
rdanusha

Reputation: 923

Try like bellow,

RewriteEngine on    
RewriteRule ^/page/([a-zA-Z-0-9-]+)$ $1/single.php?name=$2 [NC]

Upvotes: 0

Related Questions