0

I have created following pages such as

Index_inner.php
info_inner.php
video_inner.php
comment_inner.php

and many more

I want to redirect

*_inner.php -> *.php

For example

Index_inner.php -> index.php
info_inner.php -> info.php

I am redirecting using following .htaccess code.

RewriteRule info_inner.php info.php

But, how to redirect all (*_inner) pages by using one coded sentence.

Charles
  • 1,121
  • 19
  • 30
Dipak
  • 931
  • 14
  • 33

1 Answers1

1

You could do this via a rewriterule and applying a regex.

RewriteEngine on

RewriteRule ^(.+)_inner\.php$ /$1.php [R=301,L]
Charles
  • 1,121
  • 19
  • 30
  • Thanks @Charles, URL is redirected. But another problem - this code consider htdocs as my web directory. It redirect as following format **(localhost:8080/news/index_inner.php -> localhost:8080/dashboard), (localhost:8080/news/info_inner.php -> localhost:8080/info.php)**. I think it is **base directory** issues. How to fix it ? Please guide me.. My website directory is **NEWS** and, it uses 8080 port. – Dipak Aug 26 '17 at 04:34
  • 1
    With a redirect you should use an absolute URL. The reason it's going to the root is because of the `/$1.php`. If you changed it to `$1.php` (or `/news/$1.php`) it should do what you want. However, like I said it would be better to do it with an absolute URL (i.e. `RewriteRule ^news/(.+)_inner\.php$ http://localhost:8080/news/$1.php [R=301,L]`) – Charles Aug 26 '17 at 04:38
  • 1
    See https://stackoverflow.com/a/1564275/1168379 for why it should be absolute. And yes they did update the standard recently, however some crawlers/browsers/clients may not handle them as you expect them to. Using an absolute URL gives a clear signal on where you want to redirect the URL to (protocol, port, etc). – Charles Aug 26 '17 at 04:41
  • It works. @Charles Thank you for your help and prompt reply. – Dipak Aug 26 '17 at 05:13