开发者

mod_rewrite to transform old request urll into new one

开发者 https://www.devze.com 2023-01-06 12:00 出处:网络
.hello - i need to transform old url requests to fit into the new sites content; ie \'art-consultancy\' used to be \'consultancy\' so how can i grab \'consultancy\' urls and transform them into \'art

.hello - i need to transform old url requests to fit into the new sites content;

ie 'art-consultancy' used to be 'consultancy' so how can i grab 'consultancy' urls and transform them into 'art-consultancy'

MY RULE if ^consultancy$ MAKE ^art-consultancy$ and continue to the rules below...

RewriteRule ^art-consultancy$ consultancy-02.php [L]
RewriteRule ^art-consultancy/$ consultancy-02.php [L]

RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)$ consultancy-02.php?section=$1 [L]
Rewri开发者_运维问答teRule ^art-consultancy/([a-zA-Z0-9\-]+)/$ consultancy-02.php?section=$1 [L]
#
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ article-01.php [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ article-01.php [L]

any help appreciated!

ps. tried Redirect /consultancy /art-consultancy without any luck. Think this method needs an actual file?

best, Dc


You basically just have to do exactly what you said you wanted to do, in a similar way that you've done with the other rules, so I'm not sure how much this qualifies in the way of an "answer"...But, for the sake of completeness, I'll go ahead and write up the full thing:

(Also, I condensed your other rules into single lines)

# Add in this condition because consultancy-02.php matches here too
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^consultancy(.*)$ art-consultancy$1

RewriteRule ^art-consultancy/?$ consultancy-02.php [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/?$ consultancy-02.php?section=$1 [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ article-01.php [L]

If you wanted consultancy to be transformed to art-consultancy in the user's browser URL, you should replace the first RewriteRule with this:

RewriteRule ^consultancy(.*)$ /art-consultancy$1 [R=301,L]

I'm not entirely sure why the Redirect didn't work like you expected it to though. If you look at your server's error_log it might tell you, but otherwise it's hard to speculate without knowing what your site's directory structure looks like.

0

精彩评论

暂无评论...
验证码 换一张
取 消