1

I have an application whose codebase is deployed inside a folder shop . The URL to the main application is http://myapp/shop/.

One of the links on my page reads

http://myapp/shop/website-design/design-urself.php

which I want to redirect to http://myapp/shop/website-design/index.php

The rule which I am using in my .htaccess file is :

RewriteEngine On
RewriteBase /
RewriteRule ^/website-design/design-urself.php /website-design/index.php [R=301]

But the link is wrongly being getting redirected to http://myapp/website-design/index.php

I tried by removing the leading slash (/) from the urls as :

RewriteRule ^website-design/design-urself.php website-design/index.php [R=301]

but still it doesn't work.

I can understand that probably changing the RewriteBase to shop will solve my problem.

However , the thing here is - going further, the folder name ("shop" in my case) can change . So , in that case I have to again go and modify the .htaccess , which is not desirable.

What is the appropriate RewriteRule I should use in this case?

UPDATE : I have my .htaccess file located at my document root , i.e, inside the folder shop and outside of all other folders residing inside shop.

deGee
  • 781
  • 1
  • 16
  • 34
  • 1
    Actually you pretty much already answered your own question. You need to use a RewriteBase of shop and don't add leading slashes. There is no way to do a dynamic rewritebase so you will have to change it every time. – Panama Jack Jun 24 '15 at 14:15
  • ok...but can I dynamically set the RewriteBase using the server variables ? at least that will resolve my issue . I am not much accustomed to the htaccess rules , that's why posted it here. – deGee Jun 24 '15 at 14:35
  • No you can not in `RewriteBase` but there is some **trickery** that can be done with env vars and this post already explains this. http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically – Panama Jack Jun 24 '15 at 14:38

0 Answers0