Remove .php

New to mod_rewrite? This is a good place to start.

Problem

Postby puneetbrar » Mon May 11, 2009 7:46 am

besides is my file .htaccess
Options +FollowSymlinks
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
#RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^about.php /about [R,NC]
RewriteRule index.php$ http://www.okidda.com/ [R,NC]
#RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
#RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
#RewriteRule ^/?([a-zA-Z0-9]+)$ $1.php [L]
#RewriteRule ^(.*)\123.html$ $1.php [NC]
#RewriteRule ^(.+)\.html$ http://google.co.in/ [R,NC]
#RewriteRule ^story/([^/]+)/([^/]+).id /story.php?id=$1 [NC]
#RewriteRule ^about.php$ http://www.okidda.com/about [L]
#RewriteRule ^/?([a-z]+)$ $1.php [L]

and i want my extension to hide in url
like
www.mysite.com/about.php
to
www.mysite.com/about

can anybody help
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

Postby richardk » Mon May 11, 2009 8:27 am

Try
Code: Select all
Options +FollowSymLinks +Indexes

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /(.+/)?index\.(html?|php)(\?.*)?\  [NC]
RewriteRule ^((.+)/)?index\.(html?|php)$ /$2 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+)(\.php|/)$ /$1 [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*[^/])$ /$1.php [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Mod_rewrite

Postby puneetbrar » Mon May 11, 2009 11:04 pm

now that worked fine it was great but some issues came in as
all . php extensions got hidden
which i don't want

i want some specific urls to hide and not all like

http://www.mysite.com/story.php?id=7
to
http://www.mysite.com/story/37

second

http://www.mysite.com/tag.php?tag=rajiv ... %20airport

to

http://mysite.com/tag/37

Third

http://www.mysite.com/about.php
to
http://www.mysite.com/about


fourth

http://www.mysite.com/contact.php

to
http://www.mysite.com/contact

Fifth

http://www.mysite.com/story.php?id=7

to
http://www.mysite.com/story/37


can you please help me with this i will be thankful to you
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

Postby richardk » Tue May 12, 2009 9:37 am

Stop spamming. Only create one post for your question.

all . php extensions got hidden
which i don't want

What files should it be done to? Just /about and /contact?

http://www.mysite.com/story.php?id=7
to
http://www.mysite.com/story/37

Why 7 to 37? Where would 8 go to?

http://www.mysite.com/tag.php?tag=rajiv%20gandhi%20international%20airport

to

http://mysite.com/tag/37

Not /tag/rajiv%20gandhi%20international%20airport?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

i was not sapamming

Postby puneetbrar » Wed May 13, 2009 1:05 am

as there i no refference of any website

i was just trying to share my questions so any answer please
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

Anybody to help

Postby puneetbrar » Thu May 14, 2009 6:57 am

Hi there

thanks for al the help you are doing but nothing seems to work attached is
the .htaccess file
the only thing that worked til now are two rules
1.) RewriteRule index.php$ http://www.okidda.com/ [R,NC]

2.)#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ http://www.okidda.com/story/%1.php [QSA,L]

but when this works then i get an error page cannot be displayed
and url i get is

http://www.okidda.com/story/13.php?id=13

same is the case with about.php
which i want

http://www.okidda.com/about.php
to
http://www.okidda.com/about


Options +FollowSymLinks +Indexes
#Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule index.php$ http://www.okidda.com/ [R,NC]


RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [R=301,NC,L]
#RewriteRule ^tag/37/?$ http://www.okidda.com/tag.php?tag=ra...al%20airpo rt [NC,L]
#RewriteRule ^about/?$ http://www.okidda.com/about.php [NC,L]
#RewriteRule ^contact/?$ http://www.okidda.com/contact.php [NC,L]
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [NC,L]



#RewriteRule ^([a-z]+)\tag.php$ /numbers.html [R,NC,L]
#RewriteRule ^([a-zA-Z0-9_-]+)tag.php tag.php?id=$1
#RewriteRule ^([a-zA-Z0-9-&_]+)(/)?(.php)?$ story.php?id=$1
#RewriteRule ^/tag/([^/\.]+)/?$ /tag.php?tag=$1 [NC,L]
#RewriteRule ^/CATEGORY/([^/\.]+)/TITLE/?$ /story.php?id=$1 [NC,L]
#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ http://www.okidda.com/story/%1.php [QSA,L]
#RewriteRule about about.php
#RewriteRule about.php$ http://www.okidda.com/about [R,NC]

#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ http://okidda.com/story/%1.php [QSA,L]


#RewriteRule about.php http://www.okidda.com/about [R,NC]
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [NC,L]
#RewriteRule ^tag/37/?$ http://www.okidda.com/tag.php?tag=rajiv ... %20airport [NC,L]
#RewriteRule ^about/?$ http://www.okidda.com/about.php [NC,L]
#RewriteRule ^contact/?$ http://www.okidda.com/contact.php [NC,L]
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [NC,L]
#RewriteCond %{HTTP_REFERER} !^$
#RewriteCond %{HTTP_REFERER} !^http://okidda.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://okidda.com$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.okidda.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.okidda.com$ [NC]
#RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [NC,L]
#RewriteRule ^about.php/?$ http://www.okidda.com/about [NC,L]
#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ http://okidda.com/story.php/%1.php? [R=302,L]
#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^page\.php$ http://mydomain.site/page/%1.php [R=302,L]
#http://www.okidda.com/story.php?id=13

#Options +FollowSymLinks
#RewriteRule ^about\.php$ /about/about? [R=301,L]


#Redirect 301 /about.php /about.php
#Redirect 301 /ask-bob.php?ID=6 http://mydomain.com/ask-bob/new-page-title?
#Redirect 301 /place-to-be.php http://mydomain.com/new-section/?
#Redirect 301 /place-to-be.php?placeID=2 http://mydomain.com/new-section/new-page-title?

#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
# RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule .* index.php [QSA,L]
#</IfModule>



#RewriteCond %{QUERY_STRING} ^(.*&)?id=6(&.*)?$ [NC]
#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [R=301,NC,L]
#RewriteRule ^story\.php$ /story/id? [R=301,L]
#RewriteRule ^story/37/?$ http://www.okidda.com/story.php?id=7 [R=301,NC,L]
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

Postby richardk » Fri May 15, 2009 8:34 am

http://www.mysite.com/story.php?id=7
to
http://www.mysite.com/story/37

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?id=7(&.*)?$ [NC]
RewriteRule ^story\.php$ /story/37? [R=301,L]


http://www.mysite.com/tag.php?tag=rajiv%20gandhi%20international%20airport
to
http://mysite.com/tag/37

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?tag=rajiv%20gandhi%20international%20airport(&.*)?$ [NC]
RewriteRule ^tag\.php$ /tag/37? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

problem is there

Postby puneetbrar » Fri May 15, 2009 9:02 am

hi there thanks for all the help once again but issues
still prevail

the rules you sent are not working

the query string you sent was

RewriteCond %{QUERY_STRING} ^(.*&)?id=7(&.*)?$ [NC]
this never worked
but rule worked perfectly fine

but i tried this

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^story\.php$ /story/37? [R=301,L]

the url i got was

http://www.okidda.com/story/37
but also got error 404 the page you are looking for is not available



one thing more i want

http://www.okidda.com/about.php

to

www.okidda.com/about

and also

http://www.okidda.com/contactus.php

to

http://www.okidda.com/contactus


now my htaccess file is as below

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#RewriteCond %{HTTP_REFERER} !^$
#RewriteCond %{HTTP_REFERER} !^http://okidda.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://okidda.com$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.okidda.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://www.okidda.com$ [NC]
#RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
#RewriteRule index.php$ http://www.okidda.com/ [R,NC]
#RewriteCond %{QUERY_STRING} ^tag=([a-z]*)$
#RewriteRule ^tag\.php$ http://okidda.com/tag/%1.php? [QSA,L]

#RewriteRule ^category/([0-9]+)\.htm$ /category.php?cat_id=$1 [L]

#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ http://okidda.com/story/%1.php [QSA,L]

#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteCond %{QUERY_STRING} ^(.*&)?id=7(&.*)?$ [NC]
#RewriteRule ^story\.php$ /story/37? [R=301,L]

#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
#RewriteRule ^story\.php$ /story/37? [R=301,L]


thanks a lot once again
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

problem is there

Postby puneetbrar » Fri May 15, 2009 9:08 am

No spamming

when i use this rule

#RewriteRule ^about\.php$ /about/ [R=301,L]

url i get what i want bu again error 404
http://www.okidda.com/about/

please help
puneetbrar
 
Posts: 8
Joined: Mon May 11, 2009 7:41 am

Postby richardk » Fri May 15, 2009 9:36 am

One issue at a time.

Remove everything from your .htaccess file and try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?id=7(&.*)?$ [NC]
RewriteRule ^story\.php$ /story/37? [R=301,L]

RewriteRule ^story/37/?$ story.php?id=7 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 104 guests

cron