user3114190
user3114190

Reputation:

Remove subfolder from URL

I'm going to create pretty links in URL-address.

For example I have:

mysite.com/language/en/

And remove language folder from url:

mysite.com/en/

I wrote in .htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule ^language/(.*)$ /$1 [L,R]
</IfModule>

It's working fine, but mysite.com/en/ should has content of mysite.com/language/en/. Now I have 404 error.

How can I do it?


Update (Full .htaccess) :

Options All -ExecCGI -Indexes -Includes +FollowSymLinks

# Bad Request
ErrorDocument 400 /error/400.html

# Authorization Required
ErrorDocument 401 /error/401.html

# Forbidden
ErrorDocument 403 /error/403.html

# Not found
ErrorDocument 404 /error/404.html

# Method Not Allowed
ErrorDocument 405 /error/405.html

# Request Timed Out
ErrorDocument 408 /error/408.html

# Request URI Too Long
ErrorDocument 414 /error/414.html

# Internal Server Error
ErrorDocument 500 /error/500.html

# Not Implemented
ErrorDocument 501 /error/501.html

# Bad Gateway 
ErrorDocument 502 /error/502.html

# Service Unavailable
ErrorDocument 503 /error/503.html

# Gateway Timeout
ErrorDocument 504 /error/504.html

#Rewrite links
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^language/(.*)$ /$1 [L,R]
</IfModule>

<ifModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

<ifModule mod_headers.c>
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "max-age=43200, public"
    </FilesMatch>
    <FilesMatch "\.(js|css|txt)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
    <FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png)$">
        Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
    <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
        Header unset Cache-Control
    </FilesMatch>
</IfModule>

Upvotes: 1

Views: 841

Answers (1)

anubhava
anubhava

Reputation: 784898

Have your rules like this:

#Rewrite links
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+language/(\S*)\sHTTP [NC]
RewriteRule ^ /%1 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!language/)(.+)$ language/$1 [L,NC]
</IfModule>

Upvotes: 1

Related Questions