简体   繁体   中英

301 Redirect for specific url

I want to edit the URL of a page (only one page called meto.php ) to a custom URL.

It is important that the meto.php file located in sub-directory /pob/ i want to change this www.domain/pob/meto.php to www.domain/pob/define.php

When visitor type this address www.domain/pob/meto.php address bar show this address: www.domain/pob/define.php

Please note define.php file does not exist.

I tried this code in .htaccess file at /pob/ (not root directory):

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/pob/$1 [r=301,nc]
Redirect 301 meto.php define.php

//also
    Redirect 301 /meto.php http://www.domain.com/pob/define.php

//

RewriteRule ^meto.php define.php

Unfortunately all of the above tries fails.

Server info:

Apache Version 2.2

PHP: 5.5

You can not rewrite your files using Redirect Directiv of mod_alias , it is used for external redirection.

Try mod_rewrite

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/pob/$1 [R=301,L]
#1) redirect "/pob/meto.php to "/pob/define.php"
RewriteCond %{THE_REQUEST} /meto.php [NC]
RewriteRule ^ /define.php [NC,L,R]

 #2) rewrite "pob/define.php" to "/pob/meto.php"
 RewriteRule ^define\.php$ /pob/meto.php [NC,L]

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