Via an htaccess, I want to remove this point inside url : Products/Description
example : https://test.com/Products/Description/logitech/Id-12
I tried this but it does not work.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Products/Description/$1$2 [L]
below is my complete htaccess tried rules file:
RewriteEngine On
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)//+[?\s]
RewriteRule ^ %1 [R=302,L]
# Reroute to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Remove Products/Description ===> not working
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Products/Description/$1$2 [L]
With your shown samples and efforts, please try following .htaccess rules file. We need to do few changes in it. Make sure that your .htaccess file is residing along with Products folder(not inside it, besides it).
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /Products/Description/
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L,NE]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)//+[?\s]
RewriteRule ^ %1 [R=302,L]
RewriteCond %{THE_REQUEST} \s/index\.php\?([^&]*)&([^&]*)&Id=(\d+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Products)/(Description)/(\d+)/?$ index.php?$1&$2&Id=$3 [QSA,NC,L]
# Reroute to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Related
I'm trying to rewrite matching URLs of my website but it's not working for some reason, don't know why...
Here is current URL:
example.com/details.php?p=10&text=some-text-is-here
want to write like this
example.com/post-details/10/some-text-is-here
My .htaccess is here
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/details\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /details/%1? [R=301,L]
RewriteRule ^details/([0-9]+)$ /details.php?id=$1 [L]
any help would be appreciated
Try this :
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/details\.php\?p=(\d+)&text=(.+)\s [NC]
RewriteRule ^ /post-details/%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteRule ^post-details/(\d+)/(.+)$ /details.php?p=$1&text=$2 [L,NE]
Note: clear browser cache the test
I am trying to rewrite the url example.com/parts/toolbucket/part.php?id=1 into example/toolbucket/part/1
I have most of the .htaccess working but the last part of the rewrite doesn't work.
This is my .htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
Any ideas?
Because you are missing the directory part in the rule. If you want your URL to be this example.com/toolbucket/part/1
Replace this
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
With this.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^toolbucket/part/([0-9]*)/?$ /parts/toolbucket/part.php?id=$1 [L]
I need some help to get friendly URL's on my website.
These are my links i need to rewrite:
www.example.com/index.php?page=pagename
www.example.com/index.php?page=profile&id=number
This is my .htaccess. I solved the issue for the first link, however I can't do it for the second one.
I would like to have for the second link:
www.example.com/profile/name or
www.example.com/profile/id
This is my .htaccess file:
# for www.example.com/index.php?page=profile&id=number
RewriteCond %{THE_REQUEST} \?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]
# for www.example.com/index.php?page=page
RewriteCond %{THE_REQUEST} \?page=([^&\ ]+)($|\ )
RewriteRule ^ /%1? [L,R=301]
# rewrites back
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
The code I submitted above solved my problem.
You can use:
# for www.example.com/index.php?page=profile&id=number
RewriteCond %{QUERY_STRING} page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R=301]
# for www.example.com/index.php?page=page
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^ /%1? [L,R=301]
And for rewrites back
# rewrites back
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&id=$2 [L]
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
I have two different domains who I want to point to separate folders on my server.
This .htaccess file is what I have currently
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /foo/index.html [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /bar/index.html [R,L]
(Note that the [R] option is only there so I can see what is (not) happening while testing)
It works fine if one goes to www.foo.com/asdf or www.bar.com/something
However, simply going to www.foo.com or www.bar.com (with or without the www. subdomain) won't trigger these rules for some reason.
What am I doing wrong?
It is happening due to RewriteCond %{REQUEST_FILENAME} !-f failing for your home page (index.php or index.html) since either of those files will be found. You set your rules like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /foo/index.html [L]
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com [NC]
RewriteRule ^index\. /foo/index.html [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /bar/index.html [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com [NC]
RewriteRule ^index\. /bar/index.html [L]
I would like to pass (not redirect) something like this:
http://www.example.com/ (with / optional)
passed to the script
http://www.example.com/index.php
http://www.example.com/foo/ (with / optional)
passed to the script
http://www.example.com/index.php?nav=foo
http://www.example.com/foo/bar (with / optional)
passed to the script
http://www.example.com/index.php?nav=foo&subnav=bar
Furthermore I would like to pass the subdomain http://testumgebung.example.com to http://www.example.com/testumgebung.php with the same parameters as above.
I just managed to do the following, but it rewrites the url in the browser bar to the passed location and doesn't leave the url as before:
RewriteCond %{HTTP_HOST} ^testumgebung\.maskesuhren\.de
RewriteRule ^(.*)$ http://www.maskesuhren.de/$1/testumgebung.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]+/?$
RewriteRule ^([^/]*)/?$ index.html?nav=$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /.*/.*
RewriteRule ^([^/]*)/([^/]*)$ index.html?nav=$1&subnav=$2 [R,L]
You want to get rid of the R in the last 2 rules:
RewriteCond %{HTTP_HOST} ^testumgebung\.maskesuhren\.de
RewriteRule ^(.*)$ http://www.maskesuhren.de/$1/testumgebung.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]+/?$
RewriteRule ^([^/]*)/?$ index.html?nav=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /.*/.*
RewriteRule ^([^/]*)/([^/]*)$ index.html?nav=$1&subnav=$2 [L]
The R in the square brackets tell mod_rewrite to redirect the browser, which changes the URL in the browser's location bar.
.
I had to change the order to achive what I wanted
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/[^/]+/?$
RewriteRule ^([^/]*)/?$ ?nav=$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /.*/.*
RewriteRule ^([^/]*)/([^/]*)$ ?nav=$1&subnav=$2 [R,L]
RewriteCond %{HTTP_HOST} ^testumgebung\. [NC]
RewriteRule ^$ testumgebung.html [L]
and to rewrite the html so that the external resources start with a slash.