Nicolas Munera
Nicolas Munera

Reputation: 58

How to delete a subdirectory from a URL?

So I'm trying to turn my website from this:

http://profe5.com/Profe5-Web/public_html/login.html

To this:

http://profe5.com/login

I've been struggling to do this, but whenever I run it I get 404 error!

This is my htaccess:

    DirectoryIndex Profe5-Web
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
    RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.html [R=301,L]
    RewriteRule ^Profe5-Web/public_html/(.*)$ $1 [R=301,L]

It would be so awesome if you guys could help me! Thanks so much!

Upvotes: 1

Views: 76

Answers (3)

anubhava
anubhava

Reputation: 784898

This should be your complete .htaccess:

DirectoryIndex Profe5-Web
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Profe5-Web/public_html/([^.]+)\.html [NC]
RewriteRule ^ %1? [R=301,L]

# internal forward from pretty URL to actual one
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ Profe5-Web/public_html/$1.html [L,QSA]

Upvotes: 1

Sean Johnson
Sean Johnson

Reputation: 5607

If you want /login to map to Profe5-Web/public_html/login.html - try this:

RewriteRule ^([^.]+)$ Profe5-Web/public_html/$1.html [R=301,L]

The RewriteRule you already have, RewriteRule ^([^\.]+)$ $1.html [R=301,L] will map /login to /login.html, which doesn't seem to do what you need it to.

Upvotes: 0

jmadsen
jmadsen

Reputation: 3675

you might consider instead doing this via a virtual host; check with your hosting company about setting it up

Upvotes: 0

Related Questions