mod_rewrite does not return $_GET-value? - mod-rewrite

I have a problem with mod-rewrite, to be more precise, it doesn't redirect me properly. Everything works fine on my local server, the problem only occurs when the site goes live... This is what I have in the .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(tutorial|news|out|profile|script)/([0-9]+)/?$ $1.php?id=$2 [L]
RewriteRule ^(tutorial|news)/([0-9]+)/post-comment/?$ $1.php?id=$2&action=postcmt [L]
RewriteRule ^atelier/([0-9]+)/?$ img/gallery/view.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9]+)/page/([0-9]+)/?$ $1.php?page=$2 [L]
RewriteRule ^get/([a-zA-Z0-9]+)/([0-9]+)/?$ $1/get.php?id=$2 [L]
RewriteRule ^get/brushes/(abr|img)/([0-9]+)/?$ brushes/$1.php?id=$2 [L]
RewriteRule ^([a-zA-Z0-9]+)/(c|series|type)/([0-9]+)/page/([0-9]+)/?$ $1.php?$2=$3&page=$4 [L]
RewriteRule ^([a-zA-Z0-9]+)/(c|series|type)/([0-9]+)/?$ $1.php?$2=$3 [L]
RewriteRule ^design/preview/([0-9]+)/?$ design/preview.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9]+)/send/?$ $1.php?action=send [L]
RewriteRule ^askme/post-question/?$ ask.php?action=ask [L]
If I enter news/5/ for example, it will only redirect me to news.php, design/preview/5 will only take me to design/preview.php and so forth. On the contrary, get/brushes/abr/1 works fine... I have no idea what I'm doing wrong, any suggestions?

MultiViews could cause this behavior. Try to disable it:
Options -MultiViews

Just to start from the simplest place and add complication after, does this work for you?
RewriteRule ^news/([^/\.]+)/?$ news.php?id=$1 [L,NC]

Related

Laravel htaccess, redirect url if find /en

My old url
www.example.com/cn/news
www.example.com/cn/event
I want to if user enter /cn url Laravel will redirect into this url
www.example.com/en/news
www.example.com/en/event
here is my laravel .htaccess in root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I try this one but it doest work
RewriteCond %{THE_REQUEST} /cn [NC]
RewriteRule ^ /%1/en/%2/? [L,R=301]
UPDATE
now .htaccess look like this but still didnt work
RewriteEngine On
RewriteRule ^(.)$ public/$1 [L]
RewriteRule ^cn/(.)$ en/$1 [L,R=301]
RewriteRule ^cn/?(.*)$ en/$1 [L,R=301]
This rule alone should work.
Match a cn prefix with an optional / and capture all characters after the /.

mod_rewrite with 2 vars works, but URL changes

I got some problem with my htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^contact/ index.php?p=contact [L]
RewriteRule ^imprint/ index.php?p=imprint [L]
RewriteRule ^escort-rates/ index.php?p=escort-rates [L]
RewriteRule ^discretion-reliability/ index.php?p=discretion-reliability [L]
RewriteRule ^(escort-model)/(\.*)/$ index.php?p=$1&l=$2 [L]
If I call www.domain.com/contact/ the URL won't change visible, but is internally directed to index.php?p=contact, it works with the other 3 ones also.
But if I call www.domain.com/escort-model/escortname/ the URL changes visible to the visitor.
The correct page is called, but the URL changes to index.php?p=escort-model&l=escortname
Any hint would be greatly appreciated.
I think it should be (without the parenthesis):
RewriteRule ^escort-model/(.*)/$ index.php?p=$1&l=$2 [L]
instead of:
RewriteRule ^(escort-model)/(.*)/$ index.php?p=$1&l=$2 [L]

mod-rewrite weird behaviour on rewriterule

My .htaccess file looks like this:
Options +FollowSymlinks
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [R=301,L]
RewriteRule ^product/([0-9]+)/*. /tags.php?id=$1 [NC,L]
RewriteRule ^page/([a-zA-Z0-9_-]+)$ /site.php?page=$1 [NC,L]
I wanted the last rule to be:
RewriteRule ^site/([a-zA-Z0-9_-]+)$ /site.php?page=$1 [NC,L]
If I change the last rule, it does not work at all. I get a 404 not found.
I have no idea why it doesn't work, is the word 'site' a registered word or...?

Mod rewrite tags

my URL is like this.
http://site.org/index.php?page=tags&tag=tagname
I'd like to rewrite it to
http://site.com/tags/tagname
My current .htaccess
RewriteEngine On
# RewriteRule ^/?([a-z]+)$ $1.php [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)$ index.php?paste=$1 [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)/edit$ index.php?paste=$1&page=edit [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+).txt$ index.php?paste=$1&paste_txt=$1 [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+).txt$ index.php?paste=$1&paste_txt=$1 [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)/delete$ index.php?paste=$1&page=delete [L]
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+).download$ index.php?paste=$1&paste_download=$1 [L]
RewriteEngine on
RewriteRule ([^/\.]+)/?.cgi$ index.php?page=$1 [L]
#RewriteEngine on
#RewriteRule ([^/\.]+)/?.txt$ index.php?paste_txt=$1 [L]
#RewriteEngine on
#RewriteRule ([^/\.]+)/?.download$ index.php?paste_download=$1 [L]
RewriteRule ^/?([A-za-z0-9]+)/([A-za-z0-9]+)$ index.php?page=$1&tag=$2 [L]
I believe this should do it... That is if you want numbers in your tags. If not, remove the 0-9 from each part of it.

double redirect mod_rewrite

I am trying to configure a .htaccess file to my webpage to make it work as i want, but after a lot of searching and trying to understand the documentation, my head is just confused about these mod_rewrite.
It looks like this:
root/index.php
root/application/-subfolders-
root/config/-files-
root/library/-files-
what i want is everything sent to the index.php file as a parameter like index.php?page=$i, so i can have links like www.mypage.com/foo/bar and my index.php handles it.
ALSO i want to have the www.mypage.com/js/filename be sent to a subfolder in application,
like root/application/javascripts/filename.
I just cant get this to work, tried different answer i found both here and other places.
.htaccess at is now:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/js/ application/javascripts/ [L]
RewriteRule ^/js/(.*)$ application/javascripts/$1 [L]
RewriteRule ^css/ application/css/ [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]
RewriteRule ^images/ application/images/ [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php?page=$1 [NC]
</IfModule>
This should do it:
RewriteEngine on
RewriteRule ^js/(.*)$ application/javascripts/$1 [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [NC]

Resources