简体   繁体   中英

Want to hide page name in url

I just need to know how can I stop displaying my php pages name in url
for example:

http://cbse.in/classxii/question_papers.php to http://cbse.in/classxii/ or http://cbse.in/classxii/question_papers/

http://cbse.in/classxii/computer_science/question_papers.php to http://cbse.in/classxii/computer_science/ or http://cbse.in/classxii/computer_science/question_papers/

http://cbse.in/classxii/computer_science/Chapter1/answers.php to http://cbse.in/classxii/computer_science/Chapter1/ or http://cbse.in/classxii/computer_science/Chapter1/answers/

I came to know this is possible by URL rewriting in htaccess.

But not clear idea on this, it will great if someone show me the correct and clear way to do this.

Please refer this link for info about htaccess redirection. Also, pls make sure that you've got it enabled within Apache, the webserver.

http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

try this:

RewriteEngine on

#unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L]

#redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.*)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.*)\.php$ $1 [R=301,L]

#resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

You need to use Mod Rewrite. You can use this one Mod Rewrite generator: http://www.generateit.net/mod-rewrite/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM