1

I can make the following URL:

  • example.com/video1

redirect to:

  • example.com/video/video1.php

but I would like it to display:

  • example.com/video1

in the browser but it is not.

It is displaying:

  • example.com/video/video1.php

And when I go to URL:

  • example.com/video/video1.php

it should display

  • example.com/video1

in the browser but it is displaying:

  • example.com/video/video1.php

How do I do this?

Here is what I am using:

RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1  [R=301,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
Angelo Rodriguez
  • 127
  • 2
  • 14
  • 1
    There are already several questions regarding this topic. Please check: http://stackoverflow.com/questions/18803615/htaccess-rewriterule-to-path-without-changing-url, http://stackoverflow.com/questions/14895980/htaccess-redirect-without-changing-url, http://stackoverflow.com/questions/20847256/htaccess-redirect-domain-to-subdirectory-without-changing-url – mario.van.zadel Feb 26 '16 at 06:44
  • 1
    And regarding your "reverse mod rewrite" you shoud check this: http://stackoverflow.com/questions/5573485/php-htaccess-pretty-url-in-reverse – mario.van.zadel Feb 26 '16 at 06:45
  • @mapek I know there are many similar questions and I've tried all the suggestions but it is still not working. I've already spent so may hours on this one issue which seems like something so simple. And every time I try to post a question to try to get help, people just reply with a link to another question that I've already seen and tried. And I am getting so frustrated because I can't figure out what I am doing wrong. For some reason I can't get the pretty URL to display in the browser address bar – Angelo Rodriguez Feb 26 '16 at 07:52
  • @mapek and my URLs are not dynamic URLs. All of the questions I see are referring to dynamic URLs. – Angelo Rodriguez Feb 26 '16 at 07:55
  • Ok, I'll try to help you. Please check the answer I've added. – mario.van.zadel Feb 26 '16 at 08:27
  • @mapek That didn't work either. I just accidentally left it out when I typed the question. I think there might be an issue with my hosting provider. Because the mod_rewrite does not seem to be working. I'm using Network Solutions for my hosting. I have already called them but they are saying that it is on by default. But it is not working. I've also tried adding basic rules like removing the php extension from the URL and that doesn't work either. Would you know what could possibly be the issue? – Angelo Rodriguez Feb 26 '16 at 08:49

3 Answers3

1

You can use the following rules in /root/.htaccess

RewriteEngine on
#1--Redirect from "/videos/foo.php" to "/foo"--#
RewriteCond %{THE_REQUEST} /videos/([^.]+)\.php [NC]
RewriteRule ^ /%1 [NE,NC,L,R]
#2--Internally map "/foo" to "/videos/foo.php--#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /videos/$1.php [NC,L]

Clear your browser's cache before testin this.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
0

Have you tried

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]

Source:

https://www.branded3.com/blog/htaccess-mod_rewrite-ultimate-guide/

Jimmy Canadezo
  • 161
  • 1
  • 10
0

You forgot to add closing $ in your regex. Please try this:

RewriteEngine On
RewriteRule ^/video1$ /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php$ /video1  [R=301,L]

instead of

RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1  [R=301,L]
mario.van.zadel
  • 2,919
  • 14
  • 23