I changed a few things in my .htaccess file a few days ago and just now noticed that brackets in the URL are now messed up. Instead of:
url.com/admin/page?delete[]=12345&reasons[]=2
the URL shows as:
url.com/admin/page?delete%255B%255D=12345&reasons%255B%255D=2
What could be causing this? Here's my .htaccess file. It's driving me crazy!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]
RewriteRule ^admin/page/?$ admin/page.php [L,NC]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^.* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/profile?user=%1 [L,QSA]
RewriteRule ^([^/]*)-([0-9]+)\.html$ product?name=$1&id=$2 [L,QSA]
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
Have your rules like this:
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=302,NE]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/profile?user=%1 [L,QSA,R=302,NE]
RewriteRule ^([^/]+)-([0-9]+)\.html$ product?name=$1&id=$2 [L,QSA]
RewriteRule ^admin/page/?$ admin/page.php [L,NC]
Keep redirect rules before rewrites and use NE flag in each redirect rule.
Make sure to clear browser cache before testing.
Related
so I got this script from codester and I wasn't able to install it cause I keep getting errors like ".htaccess misconfigured" can anyone detect the error for me please, here is the .htaccess code
RewriteEngine on
RewwriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteRule page/(.*)$ page.php?slug=$1 [L]
RewriteRule py$ _py.php [L]
RewriteRule payout$ pyt.php [L]
RewriteRule contact$ ct.php [L]
Options -Indexes
ErrorDocument 404 /404.php
Help
There is a spelling mistake in your second line, use
RewriteBase /
instead of RewwriteBase /
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteRule page/(.*)$ page.php?slug=$1 [L]
RewriteRule py$ _py.php [L]
RewriteRule payout$ pyt.php [L]
RewriteRule contact$ ct.php [L]
Options -Indexes
ErrorDocument 404 /404.php
I am new to web development.
Below Htaccess code works fine in root directory files. While We try to rewrite the files in sub folder /test/downloadh.php. when i was changed below code will we can't get the root files links are notworking.
RewriteEngine on
RewriteBase /test/
Would you please suggest us, how to get the url
http://example.com/test/downloadh/the-house-on-the-borderland
to
http://example.com/test/downloadh.php?id=the-house-on-the-borderland
Working Code:-
# disable directory browsing
Options -Indexes
AddDefaultCharset UTF-8
FileETag MTime Size
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+album\.php\?Id=([^\s&]+) [NC]
RewriteRule ^ album/%1? [R=301,L]
RewriteRule ^album/([^/]+)/?$ album.php?Id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+downloada\.php\?linkb=([^\s&]+) [NC]
RewriteRule ^ downloada/%1? [R=301,L]
RewriteRule ^downloada/([^/]+)/?$ downloada.php?linkb=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:downloadb\.php)?\?mlink=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ downloadb/%1%2? [R=301,L]
RewriteRule ^downloadb/([^/]+)/([^/]+)/?$ downloadb.php?mlink=$1&linkb=$2 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:songs\.php)?\?id=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ songs/%1/%2? [R=301]
RewriteRule ^songs/([^/]+)/([^/]+)/?$ songs.php?id=$1&linkb=$2 [L,QSA]
# CUSTOM ERRORPAGE
ErrorDocument 401 /error/test.php
ErrorDocument 403 /error/test.php
ErrorDocument 404 /error/test.php
ErrorDocument 500 /error/test.php
Error Code:-
RewriteCond %{THE_REQUEST} /downloadh(?:\.php)?\?id=([^\s&]+)\s [NC]
RewriteRule ^ downloadh/%1/? [R=302,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ downloadh.php?id=$1 [NC,L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test/downloadh.php\?id=([^\s&]+) [NC]
RewriteRule ^test/downloadh\.php /%1? [R=301,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ /test/downloadh.php?id=$1 [L,QSA]
Try this code :
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(test/downloadh)\.php\?id=(.+)\sHTTP.*$ [NC]
RewriteRule ^ %1/%2? [L,R=301]
RewriteRule ^test/downloadh/([^/]+)/?$ test/downloadh.php?id=$1 [L]
I'm trying to rewrite $_GET parameters via .htaccess. I have tried doing it myself but no success. Check what I want below:
mydomain.com/system.php?id=748742
to
mydomain.com/system/748742
My /var/www/ directory: prntscr.com/ixpt1x
I have tried using this rule but my server keeps saying 500 Internal Server Error
RewriteRule ^system/(.*) /system.php?id=$1 [NC,L]
Here is my .htaccess file at this current time
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^favicon.ico images/favicon.ico [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(/|)$ $1.php [L]
ErrorDocument 404 404.php
ErrorDocument 403 404.php
ErrorDocument 500 404.php
This is the result of the discussion in the comments to the question:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^favicon.ico images/favicon.ico [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
RewriteRule ^/?system/(\d+)/?$ /system.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(/|)$ $1.php [L]
ErrorDocument 404 404.php
ErrorDocument 403 404.php
ErrorDocument 500 404.php
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^favicon.ico images/favicon.ico [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
RewriteRule ^/?system/(\d+)/?$ /system.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(/|)$ $1.php [L]
ErrorDocument 404 404.php
ErrorDocument 403 404.php
ErrorDocument 500 404.php
My .htaccess looks like this:
<FilesMatch ".(eot|ttf|otf|woff|svg)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=302,NE]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/page?user=%1 [L,QSA,R=302,NE]
***THIS IS WHERE I INSERT THE NEW RULE***
RewriteRule ^([^/]*)-([0-9]+)\.html$ product?name=$1&product_id=$2 [L,QSA]
So far so good. It all works. When someone goes to scoobydoo.domain.com for example they are redirected to domain.com/page?user=scoobydoo. Now I also want to mask the page so that when someone goes to www.domain.com/scoobydoo they are really shown domain.com/page?user=scoobydoo, so I add this:
RewriteRule ^([^/]*)$ /page?user=$1 [L]
When I add this to the 2nd last line however, it doesn't work.
What's wrong here?
Your rule is ok, but you need to exclude your real files and dirs from it :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /page?user=$1 [L,QSA]
My htaccess is as below:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# restrict .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^\ ]+\.php($|\ )
RewriteRule \.php$ / [F,L]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
RewriteRule ^good-([^-]*)-([^-]*)\.html$ /goodie?
sd=$1&sd=$2 [L]
RewriteRule ^goodies-([^-]*)-([^-]*)$ /goodie_new?
sd=$1&ds=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /goodie_new?
ds=$1&sd=$2&de=$3 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail_fm?prmn=$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
When i access blog rewrite URL i.e. http://example.com/blog/title-of-blog then i am getting 500 Internal Server Error. I tried adding RewriteCond %{ENV:REDIRECT_STATUS} ^$ but still 500 error is not disappearing.
Please let me know errors and if there is any wrong rules in myhtaccess.
Have it this way:
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{THE_REQUEST} /index\.php
RewriteRule ^index\.php$ / [L,R=301]
# skip files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# restrict .php
RewriteCond %{THE_REQUEST} \.php($|\ )
RewriteRule \.php$ / [F,L]
# remove .html
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
RewriteRule ^goodies-([^-]*)-([^-]*)$ goodie_new?sd=$1&ds=$2 [L,QSA]
RewriteRule ^good-([^-]*)-([^-]*)\.html$ goodie?sd=$1&sd=$2 [L,QSA]
RewriteRule ^blog/([^/.]+)/?$ blogdetail_fm?prmn=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ goodie_new?ds=$1&sd=$2&de=$3 [L,QSA]
# remove .php from URL
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ cityres?cityf=$1 [L,QSA]