I have tried everything from forums but no result.
How can I hide directory "example" from all url's in website.
For example when user enters:
www.domain.com/example/en/file.php or
www.domain.com/example/ru/file.php or
www.domain.com/example/de/file.php
I want him to see in the url only:
www.domain.com/en/file.php or
www.domain.com/ru/file.php or
www.domain.com/de/file.php
but conent have to be taken from
www.domain.com/example/en/file.php or
www.domain.com/example/ru/file.php or
www.domain.com/example/de/file.php
My current htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
#RewriteCond %{THE_REQUEST} /example/ [NC]
#RewriteRule ^example/(.*)$ /$1 [L,R=301,NC,NE]
#RewriteRule ^((?!example/).*)$ /example/$1 [L,NC]
NOTE:
it can be more directories in "example" than en, ru or de.
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# remove /example/ from URLs
RewriteCond %{THE_REQUEST} /example/ [NC]
RewriteRule ^example/(.*)$ /$1 [L,R=301,NC,NE]
# add www to host name
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# other than /js/ internally prefix /example/ before all URIs
RewriteCond $1 !js [NC]
RewriteRule ^((?!example/)[a-z]{2}/.*)$ /example/$1 [L,NC]
# if a matching .php file is found add .php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
you can just put this line
Options -Indexes
Related
I need a hand to redirect and write nice urls for my product requests.
So for any request like
https://www.domain.com.au/pages/product.php?product=PRODUCTNAME
Redirect and rewrite to
https://www.domain.com.au/pages/product/PRODUCTNAME
I actually have:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{SERVER_PORT} 80
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,NE,L]
# End of Apache Rewrite Rules
So it goes to:
https://www.domain.com.au/pages/product/?product=PRODUCTNAME
That, for pages like about.php etc it's fine as you may realize.
Thanks ahead!
You can use the following to shorten your Product URLs :
Put the following at top of your /root/. htaccess file.
RewriteEngine On
#redirect /pages/product.php?product=name to /pages/product/name
RewriteCond %{THE_REQUEST} /pages/product\.php\?product=([^\s]+) [NC]
RewriteRule ^ /pages/product/%1? [L,R=301]
#Rewrite the new URL to the old one
#load the contents from the OLD URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/product/([^/]+)/?$ /pages/product.php?product=$1 [L]
I have one website running in that we need to modify .htaccess. There has been the error reported by Google that URL is being appended by one more PHP file.
Such as http://www.example.com/test-file.php/test1-file.php
We need to either remove test1-file.php or redirect to the 404.php page using .htaccess
My .htaccess looks like below
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/
RewriteRule ^(.*)/$ http://www.example.com/$1 [R=301,L
<IfModule mod_rewrite.c>
RewriteEngine on
ErrorDocument 404 http://example.com/404.php
</IfModule>
You may use these rules:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}${REQUEST_URI} [L,R=301,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [R=301,L,NE]
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=302,L]
# remove content after 2nd slash
RewriteRule ^(.+\.php)/.*$ /$1 [L,NC,R=301]
I want htaccess to remove directory (/thedir/) from full URL but it's not working. I only want to remove the /thedir/ from this URL not other urls.
redirect 302 /thedir/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball https://example.com/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball
Also tried
RewriteCond %{QUERY_STRING} ^/thedir/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball
RewriteRule ^(.*)$ https://example.com/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball [R=302,L]
These examples do not remove /thedir/.
Try these rules in your .htaccess file.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+thedir/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^thedir/)^(.*)$ /thedir/$1 [L,NC]
I have a domain example.com i want to redirect it to example.com/public but /public folder should hide from the url.
I am using the below code in .htaccess to redirect, but unable to hide the folder name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ public [L]
Please help me out for this issue.
You can try this
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1
This should be your complete .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dirname/([^\s]+) [NC]// here you write your directory
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC]
try this
RewriteEngine On
RewriteRule (.*) public/$ [QSA,L]
I have an issue I can't seem to debug. I have tried many solutions and no luck.
When I access a URL with subfolder/index.php I get redirected back to the root page. If I access another page in that subfolder it works fine. I am not sure what is causing this on my code. Here is what I have.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)index$ $1 [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
Any suggestions? Thanks!
Keep your rules like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^www.domain\.com
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule ^(.+?)/$ $1 [R=301,L,NE]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]