php - htaccess RewriteRule doesn't work properly if no trailing slash -


i trying redirect 1 subdirectory using rewriterule in main directory's .htaccess file.

for example: http://website.com/subdir should rewrite http://website.com/another_dir/destination_dir user should still see http://website.com/subdir in address bar.

this works if user ends url trailing slash. example: http://website.com/subdir/ (generates 200

however, if slash omitted, 301 redirect generated , see undesired destination directory. example, http://website/subdir redirects user http://website/another_dir/destination_dir

here pertinent parts of .htaccess:

# url rewriting: rewriteengine on rewritebase /  ...  # redirect subdirectories: rewriterule ^subdir(.*)$ another_dir/destination_dir$1 [pt,nc,qsa,l] 

any assistance appreciated!

you can adjust regex in rewrite rule optionally match slash.

rewriterule ^subdir(/?.*)$ another_dir/destination_dir$1 [pt,nc,qsa,l] 

note /? after subdir. says there may or may not slash after subdir, regex match either way.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -