htaccess rewrite error - .htaccess

What is wrong with this line
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]
I'm try rewrite links from
http://mysite.com/index.php?query=2012
to
http://mysite.com/2012
But i have 500 Internal Server Error
Also here is the content from my htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^software$ index.php?type=app
RewriteRule ^movies$ index.php?type=movie
RewriteRule ^games$ index.php?type=game
RewriteRule ^music$ index.php?type=music
RewriteRule ^other$ index.php?type=other
RewriteRule ^tv$ index.php?type=tv-show
RewriteRule ^ebooks$ index.php?type=ebooks
RewriteRule ^(.*)-(\d+)\.html$ download.php?id=$2 [L,NC]
RewriteRule ^site/([^/]*)$ /index.php?site=$1 [L]
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]

Replace this rule:
RewriteRule ^([^/]*)$ /index.php?query=$1 [L]
with this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)/?$ index.php?query=$1 [L,QSA]

Related

Htaccess redirecting dynamic urls

I am trying to create redirections from the old urls to the new ones and I have a problem how to write appropriate htaccess rules.
old urls
domain.com/cat1/cat2/cat3/city,name
domain.com/cat1/cat2/city,name
domain.com/cat1/city,name
new urls
domain.com/cat1/cat2/cat3?city=name
domain.com/cat1/cat2?city=name
domain.com/cat1?city=name
I tried something like this but it doesn't work.
RewriteRule ^/city,(.*)$ /city=?$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
RewriteCond %{HTTP_HOST} ^www\.domain\.pl [NC]
RewriteRule ^(.*)$ http://domain.pl/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain.pl
RewriteCond %{HTTP_HOST} ^(.+).domain.pl
RewriteRule ^([^/]*)$ http://domain.pl/account/firma/%1 [P,L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
EDIT: As per OP's edit adding following now.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.pl [NC]
RewriteRule ^(.*)$ http://domain.pl/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain.pl
RewriteCond %{HTTP_HOST} ^(.+).domain.pl
RewriteRule ^([^/]*)$ http://domain.pl/account/firma/%1 [P,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##To deal with domain.com/cat1/cat2/cat3/city,name URLs
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2/$3?$4=$5 [L]
##To deal with domain.com/cat1/cat2/city,name URLs
RewriteRule ^([^/]*)/([^/]*)/([^,]*),(.*)/?$ $1/$2?$3=$4 [L]
##To deal with domain.com/cat1/city,name URLs
RewriteRule ^([^/]*)/([^,]*),(.*)/?$ $1?$2=$3 [L]
You can try this full .htaccess code. Make sure you don't have anything extra apart from this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)\.(domain\.pl)$ [NC]
RewriteRule ^ http://%1/account/firma%{REQUEST_URI} [P,L]
RewriteCond %{HTTP_HOST} ^www\.(domain\.pl)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/([^,]+),([^/]+)/?$ $1?$2=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Also make sure to clear your browser cache completely before testing this change.

.htaccess rewrite URL without its change

I'm trying to make www.site.com/web/name to be understood as www.site.com/web?system=name (without the change in URL)
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1?system=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ $1?system=$2
.htacceess is located in /web.
This doesn't do anything! Where is my mistake?
You may use these rules in web/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L,NE]
RewriteRule ^([\w-]+)/?$ ?system=$1 [L,QSA]

Htaccess rewrite rules with pictures

Here are my rewrite script (.htaccess)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(action|ajax|api|uploads)(.*)$ - [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
Now I have the url: http://domain.tld/uploads/users/1/pictures/1443563069.jpg
The picture exist, but i can't load it. Is something with my rewrite rule not ok?
Try this code in root .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} /(action|ajax|api|uploads) [NC]
RewriteRule ^ - [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]
Using %{THE_REQUEST} because REQUEST_URI changes to /index.php in your last rule.

Mod Rewrite file.php? to string

I have old site with links like this:
http://domain.com/image.php?690
And I would like to change it into:
http://domain.com/old690
I have tried many different Rules, fe.:
RewriteRule ^image.php?(.+) old$1 [L]
EDIT: All rules looks like:
RewriteEngine On
RewriteRule ^admin/(.*) ninja-admin/$1 [L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
RewriteRule ^image.php\?(.+) old$1 [L]
What is correct RewriteRule, and why?
You're doing it upside down.
Put this code in your htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^old([0-9]+)$ image.php?$1 [L]
RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
The rule for your images is the following
RewriteRule ^old([0-9]+)$ image.php?$1 [L]
It will forward every url like /old123 (where 123 is one or more digits) to image.php?123
EDIT: if you want to forbid direct access to image.php?xxx then you can do it this way
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/image\.php\?([0-9]+) [NC]
RewriteRule ^ old%1 [R=301,L]
RewriteRule ^old([0-9]+)$ image.php?$1 [L]
RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
I use this so http://example.com/old4444 forwards to http://example.com/image.php?file=4444.
Also, the browser will keep http://example.com/old4444 in the address bar.
RewriteCond %{QUERY_STRING} !marker
RewriteCond %{QUERY_STRING} file=([0-9]+)
RewriteRule ^/?image.php$ %1? [R=301,L]
RewriteRule ^/?old([-a-zA-Z0-9_+]+)$ image.php?marker&file=$1 [L]

htaccess problem

I given htaccess like this
Options +FollowSymlinks
RewriteEngine On
RewriteBase /xxx/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /xxx/folder/index.php [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
but giving the url like this
http://domain.com/faq
I get the page variable as index.php. I want to get faq in $_GET['page'].How can i get this?
Remove
RewriteBase /xxx/folder/
Modify
RewriteRule ^(.*)$ index.php?page=$1 [L]
to
RewriteRule ^(.*)$ xxx/folder/index.php?page=$1 [L]

Resources