My URL:
localhost/categories?DPt=MQ==&CTg=MQ==&NLs=Mw==
I want so:
localhost/product-a/departure-a/categories-a/
My htaccess:
<IfModule mod_rewrite.c>
RewriteRule ^confirmation/?$ confirmation.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)/?$ products.php?PDt2=$1 [QSA,NC,L]
RewriteRule ^/?categories/([^/]+)/?$ categories.php?DPt=$1&CTg=$2&NLs=$3 [QSA,NC,L]
</IfModule>
But it does not.
What is wrong?
This is my version of .htaccess with comments inside:
<IfModule mod_rewrite.c>
# stop rewrite if matches existing file or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* - [L]
# redirect trailing slash
RewriteRule ^(.+)/$ /$1 [R=301,L,QSA,NE]
# confirmation
RewriteRule ^confirmation$ /confirmation.php [L]
# match everything except slash to product
RewriteRule ^([^/]+)$ /products.php?PDt2=$1 [QSA,L]
# match categories
RewriteRule ^(.+)/(.+)/(.+)$ /categories.php?DPt=$1&CTg=$2&NLs=$3 [QSA,L]
</IfModule>
Related
When I add this line of code into my .htaccess file my site crashes. Here's the code:
# Force trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpg|png|jpeg|css|xml|txt|js|php|scss|webp|mp3|avi|wav|mp4|mov)$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]
And here's the original .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase / RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm trying to fix the trailing slash issue on my site.
Having the following .htaccess rules
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^dashboard/(.*)$ back/index.html [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I want to redirect all incomings requests if they match /dashboard to end with a trailing slash. But only for this case.
if I use
RewriteRule ^dashboard/(.*)$ back/index.html [L]
RewriteCond %{REQUEST_URI}dashboard /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
will fail because all my URL's are becoming a trailing slash.
How can I have a trailing slash only for this case?
Have it this way:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^dashboard/(.*)$ back/index.html [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# add / after /dashboard
RewriteRule ^dashboard$ $0/ [L,R=301,NC]
# remove / from all other URIs
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule !^dashboard/ %1 [L,R=301,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Make sure to test it after completely clearing browser cache.
Duplicate
The redirect using .htaccess doesn't redirect links with .php to without .php
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
</IfModule>
# END WordPress
Even then I could see that the example.com/example.php redirects to 404.
Any ideas or suggestions?
You must change the order of directives. Use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I am using htaccess for clean url. Which is working fine as long as the parameters doesn't carry whitespace. In which case it converts the space in %20 and I receive 404 error.
So basically the URL: http://localhost:8080/series/dynamics/admin/cleanURL/green%20apple
gives me 404 error. But URL: http://localhost:8080/series/dynamics/admin/cleanURL/greenapple works fine.
Also is there a way I can remove the directory details from the URL, I tried
RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]
But doesn't work
htaccess
<IfModule mod_rewrite.c>
Options +MultiViews
Rewriteengine on
RewriteBase /series/dynamics/admin/cleanURL/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]
Rewriterule ^([a-zA-Z0-9]+)/?$ index.php?product=$1
RewriteRule ^(.*)(\s|%20)(.*)$ /$3-$4 [R=301,L,NE]
#rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
Rewriterule ^([a-zA-Z0-9]+(.*)+)/([^/]+(.*)+)/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]
</IfModule>
You will need to add this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) series/dynamics/admin/cleanURL/$1 [L]
Then have these rules in /series/dynamics/admin/cleanURL/.htaccess:
Options +MultiViews
Rewriteengine on
RewriteBase /series/dynamics/admin/cleanURL/
RewriteCond %{THE_REQUEST} /series/dynamics/admin/cleanURL/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=302,NE]
RewriteRule ^([^\s\x20]*)[\s\x20]+(.*)$ $1-$2 [L,R=302,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
Rewriterule ^(\w+)/?$ index.php?product=$1 [L,QSA]
#rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
Rewriterule ^([a-zA-Z0-9]+(.*))/([^/]+(.*))/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]
How can I rewrite:
http://localmachine/product.php?c=water&p=Evian
into:
http://localmachine/water/evian
If I add
RewriteRule ^([A-Za-z0-9_?-]+)/([A-Za-z0-9_?-]+)(/)?$ product.php?c=$1&p=$2 [NC,L]
I'm getting a conflict I suppose at this line
RewriteRule ^(index\.php)/([^-]+)-([^/]+)(/.*)?$ /$1$4?$2=$3 [L,QSA]
This is my htaccess :
RewriteEngine On
Options -Indexes
Options +FollowSymLinks
<Files .htaccess>
deny from all
</Files>
# rewrite /user-options to /user.php?page=page
RewriteRule ^user/logout/? actions/handler.user.php?logout=true [NC,L]
RewriteRule ^user/?$ user.php [NC,L]
# edit shopping lists
RewriteRule ^user/liste/([0-9]+)/del(/)?$ user.php?page=edit-list&gid=$1&action=del [NC,L]
RewriteRule ^user/liste/(.+)$ user.php?page=edit-list&gid=$1 [NC,L]
RewriteRule ^user/([^/]+)/?$ user.php?page=$1 [L,QSA]
# rewrite /category to /index.php?c=category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php/?c=$1 [L,QSA]
# rewrite /category/brand-mybrand/country-mycountry/offer-yes/new-yes
# to /index.php/brand-mybrand/country-mycountry/offer-yes/new-yes?c=category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^-]+.+)/?$ /index.php/$2?c=$1 [L,QSA]
# rewrite /index.php/brand-mybrand/country-mycountry/offer-yes/new-yes?c=category
# converts any /name-val/ to query parameter name=val in every rewrite
# stopping when there is no part left after /index.php
RewriteRule ^(index\.php)/([^-]+)-([^/]+)(/.*)?$ /$1$4?$2=$3 [L,QSA]
# review basket & place order
RewriteRule ^shopping-cart/actions/delete/(.*)?$ actions/handler.comanda.php?action=delcart&id=$1 [NC,L]
RewriteRule ^shopping-cart/del/(.*)/? cosuldecumparaturi.php?d=true&p=$1 [NC,L]
RewriteRule ^shopping-cart/place-order/?$ comanda.php [NC,L]
RewriteRule ^shopping-cart/preview(/)?$ cosuldecumparaturi.php [NC,L]
# rewrite ajax calls
RewriteRule ^ajax/totalShoppingCart/? ajax/totalShoppingCart.php [NC,L]
# rewrite information page
RewriteRule ^informatii/([A-Za-z0-9_?-]+)/?$ pages.php?page=$1 [NC,L]