I am trying to hide the folder path from URL:
my URL :
mysitename/category/3590474628.html
mysitename/product/details/25038.html
I am trying to make a short URL like this:
mysitename/3590474628.html
mysitename/25038.html
here is my currently using .htaccess code
RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule (.*)/(.*)/(.*)/(.*)\.html$ index.php?rt=$1&opt2=$2&opt3=$3&opt4=$4 [L]
RewriteRule (.*)/(.*)/(.*)\.html$ index.php?rt=$1&opt2=$2&opt3=$3 [L]
RewriteRule (.*)/(.*)\.html$ index.php?rt=$1&opt2=$2 [L]
RewriteRule ^(.*)\.html$ index.php?rt=$1 [L]
Related
For a website I have locally, I need to set the display language as if it were a subfolder, using an htaccess file.
For example, if I choose to display the site in German, instead of displaying it like this => local_ip/test/index.php?lang=de, I would like it to be displayed like this => local_ip/test/de/ .
Also, if I type in the url without setting the language, I would like htaccess to automatically redirect to the German language, from so => local_ip/test/tour/mountain/ to so => local_ip/test/de/tour/mountain .
My current htaccess file is structured as follows:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{QUERY_STRING} ^t=(.+?)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&t=%1 [NC,L]
RewriteCond %{QUERY_STRING} ^p=([0-9]+)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&p=%1 [NC,L]
RewriteCond %{QUERY_STRING} ^t=(.+?)&p=([0-9]+)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&t=%1&p=%2 [NC,L]
RewriteCond %{QUERY_STRING} ^c=true
RewriteRule ^city/(.+?)/?$ city.php?url=$1&c=true [NC,L]
RewriteRule ^city/(.+?)$ city.php?url=$1 [NC,L]
RewriteRule ^tour/(.+?)$ tour.php?url=$1 [NC,L]
SOLVED
After several attempts and after reading several support requests posted in this community, I found a way to make the system recognise all the other rules as well. All I had to do was put them before the last rule provided by the user who supported me. Here is the final code.
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !/de/ [NC]
RewriteRule (.*) /test/de/$1 [R,L]
RewriteRule ^de/$ /test/index.php?lang=de [L]
RewriteCond %{QUERY_STRING} ^t=(.+?)
RewriteRule city/(.+?)/?$ city.php?url=$1&t=%1&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^p=([0-9]+)
RewriteRule city/(.+?)/?$ city.php?url=$1&p=%1&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^t=(.+?)&p=([0-9]+)
RewriteRule city/(.+?)/?$ city.php?url=$1&t=%1&p=%2&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^c=true
RewriteRule city/(.+?)/?$ city.php?url=$1&c=true&lang=de [NC,L]
RewriteRule city/(.+?)$ city.php?url=$1&lang=de [NC,L]
RewriteRule tour/(.+?)$ tour.php?url=$1&lang=de [NC,L]
RewriteRule ^de/(.*)$ /test/$1 [L]
You can use the following :
RewriteEngine on
#redirect URLs to include /de
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/de/ [NC]
RewriteRule (.*) /test/de/$1 [R,L]
# /test/index.php?lang=de to /test/de
RewriteRule ^de/$ /test/index.php?lang=de [END]
RewriteRule ^de/(.+)$ /test/$1 [END]
I have a subdomain created to use as cookiless domain which is like cdn.domain.com
And on the main site I have www.domain.com. Whatever I call it comes as www.cdn.domain.com. I am using cdn.domain.com to call images etc.
Here you can see actual htaccess setting
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
</IfModule>
How I can get https://cdn.domain.com without affectting any change to main domain settings?
I think you're looking for this:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Your htaccess would look like this now:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
</IfModule>
I want to force redirect any visit to my site to https.
My htaccess rules are the following:
# rewrite address
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mytestsite\.eu$ [NC]
RewriteRule ^(.*)$ https://www.mytestsite.eu/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.mytestsite.eu/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} ^(.+)\.mytestsite\.eu$ [NC]
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^ https://www.mytestsite.eu/ [L,R]
how can I achieve this?
rewrite the first three lines like this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
This url
example.com/videos/load.php?cat=video-category
would become
example.com/videos/video-category
Also, there is pagination url
example.com/videos/load.php?cat=video-category&p=2
and it would become
example.com/videos/video-category/page/2
I tried to do this.. but it doesn't work.
Here is my htaccess (into videos folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^(\w+/+/)page/?$ $1 [R=301,L]
RewriteRule ^(\w+)(?:/[^/]+)?/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^(\w+)/[^/]+/([0-9]+)/?$ load.php?cat=$1&p=$2 [L,QSA]
Put this code in your htaccess.
This should work
Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^([^/]+)/page/?$ $1 [R=301,L]
RewriteRule ^([^/]+)/page/([1-9][0-9]*)$ load.php?cat=$1&p=$2 [L,QSA]
I have created the below condition:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(shop|delivery-checkout|delivery-order|delivery-offer|confirm-sms-code|show-delivery-product|auto-search-product|add-product|update-product|remove-product|destroy-cart|get-cart|cuisine|og-shop) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/ [R=301,L]
RewriteCond $1 !^(index\.php|robots\.txt|website|shop_files|shop_list|client|favicon\.ico|style\.css|sitemap.xml)
RewriteRule ^(.*)$ ./index.php?/$1 [L]
AddCharset utf-8 .js
What I am basically trying to do is check if (https) is not present in URL.
So except URLs referred, rewrite it to https://www.
Note: I am loading those urls: domain.com/shop, domain.com/delivery-checkout, domain.com/delivery-order inside an iframe and that is why I want those excluded and secure or not depending on parent site.
What am I doing wrong?
Change your code with this:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(shop|delivery-checkout|delivery-order) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]