0

I have a wordpress site and a custom build app all on the same URL. I am looking to redirect all my CMS (custome app) URLs to a certain php controller file. Once redirected I am looking to remove the php file from the URL

e.g. www.website.com/cms redirects to www.website.com/backend.php/cms but the URL continues to display as www.website.com/cms

So far I have the following:

# Handle the custom App URLs
RewriteCond %{HTTP_HOST} ^(www.)?website.com/cms$
RewriteCond %{REQUEST_URI} !^backend.php/cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ backend.php/cms/$1

# Handle the Wordpress URLs by removing index.php
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

EDIT:

The problem is what I have does not work.

If I go to www.website.com/cms I get a 404.

If I go to www.website.com/backend.php/cms the URL does not change to www.website.com/cms, it stays as www.website.com/backend.php/cms

I am not great at .htaccess but think I am going down the correct route.

2
  • And what is your problem? Mar 8, 2017 at 21:25
  • Updated my question with more info explaining my problem
    – matty
    Mar 14, 2017 at 14:57

2 Answers 2

0

Did you try just routing by url:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/cms/(.*)$ /backend.php [L]
#or RewriteRule ^/cms/(.*)$ /yourcms/backend.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

All your magic about 'understanding' the url you do in your cms reading REQUEST_URI.

1
  • I tried this and it didn't work. My index.php URLs were affected.
    – matty
    Mar 14, 2017 at 14:57
0

I ended up fixing this myself by having the following RewriteRule

RewriteRule ^/?cms([A-Za-z0-9\-_\/]+)/?$ /backend.php [L]
RewriteRule ^/?cms /backend.php [L]

Thanks to those that tried to help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.