again a new .htaccess issue - .htaccess

One of my URL has this /index.php?page=cfeedback&status_id=2&cf_store=8 ... After applying this htaccess it shows only /index.php?page=cfeedback in the URL.
Anything can be done for this?
Some pages also are just /index.php?page=dashboard.
My .htaccess should support both in this fashion.
/dashboard for URLs /index.php?page=dashboard
/cfeedback/2/8 for URLs /index.php?page=cfeedback&status_id=2&cf_store=8
This is a continuation of this issue: .htaccess file is not working on server
My .htaccess code is
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /mydir/admin/
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+) [NC]
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
I tried adding the following code for urls having index.php?page=$1&status_id=$2 . Please let me know what I am doing wrong.
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)&status_id=([\w-]+) [NC]
RewriteRule ^ %1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?page=$1&status_id=$2 [L,QSA]
What am I doing wrong here?
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /mydir/admin/
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)&status_id=([\w-]+)&cf_store=([\w-]+) [NC]
RewriteRule ^ %1/%2/%3? [L,R]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)&status_id=([\w-]+) [NC]
RewriteRule ^ %1/%2? [L,R]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)\s [NC]
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?page=$1&status_id=$2&cf_store=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?page=$1&status_id=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]

Insert new set of rules before earlier rules:
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /mydir/admin/
RewriteCond %{REQUEST_METHOD} (TRACE|TRACK|GET|POST|HEAD)
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)&status_id=([\w-]+)&cf_store=([\w-]+) [NC]
RewriteRule ^ %1/%2/%3? [L,R]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+)\s [NC]
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?page=$1&status_id=$2&cf_store=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]

Related

htaccess rule issue in redirecting the url

I want to redirect all below pattern url to before "?" url
i.e
Xyz.com/worksheet/rebus/?random=testing11
Xyz.com/worksheet/rebus/?abc
Xyz.com/worksheet/rebus/?l=1
should be redirected to
Xyz.com/worksheet/rebus/
I tried many things but not able to succeed. How can i do using .htaccess
Rules tried
RewriteBase /worksheet/
RewriteRule ^rebus/?$ /worksheet/rebus/ [L,R=301]
Overall
RewriteEngine On
RewriteBase /worksheet/
RewriteCond %{THE_REQUEST} \s/(rebus)/\?(\S+)\s [NC]
RewriteRule ^ /worksheet/%1/ [R=301,L]
#RewriteRule ^rebus/?$ /worksheet/rebus [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ index.php?url=$2&tableName=$1&showSol=$3 [L,QSA]
Have it this way:
RewriteEngine On
RewriteBase /worksheet/
# \?\S matches at least one character after ?
RewriteCond %{THE_REQUEST} \s/(worksheet/rebus)/\?\S [NC]
RewriteRule ^ /%1/? [R=301,L]
RewriteRule ^rebus/?$ /worksheet/rebus? [L,R=301,NC]
# skip all rules for real files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?url=$2&tableName=$1&showSol=$3 [L,QSA]

htaccess force redirect when language not matches

I'm trying to redirect when user write a language which not match like example.com/mvc/fr or when write index instead of language like example.com/mvc/index.php
to example.com/mvc/en
Here is what I tried:
Options -MultiViews -Indexes
RewriteEngine On
RewriteBase /mvc/
RewriteCond %{HTTP_HOST} .*example.com [NC]
RewriteCond %{HTTP:Accept-Language} ^ar [NC]
RewriteRule ^$ https://%{HTTP_HOST}/mvc/ar/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ https://%{HTTP_HOST}/mvc/en/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ https://%{HTTP_HOST}/mvc/de/ [L,R=301]
RewriteCond %{REQUEST_URI} !^/(en|ar|de)/
RewriteRule ^ /mvc/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)/?$ index.php?lang=$1 [QSA,NC,L]
what is wrong in my code ?

.htaccess : Rewrite url, one variable to directory

I would like to know if this final result can be achieved with some htaccess rules.
On the config folder. Where * is the page's name to show as folder.
/projectdir/config/?p=* or /projectdir/config/index.php?p=*
to /projectdir/config/*/
Example
/projectdir/config/?p=page1 => /projectdir/config/page1/
/projectdir/config/index.php?p=page1 => /projectdir/config/page1/
I tried the code posted in this question, but without results
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?p=$1 [NC]
Which basically: http://localhost/index.php?page=controller To
http://localhost/controller/
You can use this code in /project/config/.htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /project/config/
RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)&p2=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,NE,L]
RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)\s [NC]
RewriteRule ^ %1? [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?p=$1&p2=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]

Htaccess issue - url with multiple parameters

I use this htaccess for multiple parameters like bank, state,district & branch.
But it only format bank not others...???
I need it for:
www.domain.com/bank/ .....(It works)
www.domain.com/bank/state/
www.domain.com/bank/state/district/
www.domain.com/bank/state/district/branch/
My htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&\s]+)
RewriteRule ^ /%2/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank= ([^&]+)&state=([^&]+)
RewriteRule ^ /%2/%3/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&]+)&state=([^&]+)&district=([^&]+)
RewriteRule ^ /%2/%3/%4/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&]+)&state=([^&]+)&district=([^&]+)&branch=([^&]+)
RewriteRule ^ /%2/%3/%4/%5/? [L,R=301]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Kindly provide solution for this...Thanks & Regards.
You need to tweak your regex and reverse order of redirect rules:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)&state=([^&\s]+)&district=([^&\s]+)&branch=([^&\s]+)\s
RewriteRule ^ /%2/%3/%4/%5/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)&state=([^&\s]+)&district=([^&\s]+)\s
RewriteRule ^ /%2/%3/%4/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank= ([^&\s]+)&state=([^&\s]+)\s
RewriteRule ^ /%2/%3/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)\s
RewriteRule ^ /%2/? [L,R=301]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.+)$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Make sure to clear your browser cache before testing this change.

htaccess rewrite get url section not working

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]

Resources