I want to redirect pages from my_site.com/gamenews.php?id={ID} to my_site.com/news/{ID}/, but can't :(
My .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/index\.php /$1/index [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule ^gamenews\.php\?id=(.*) /news/$1/ [L,R]
AddDefaultCharset UTF-8
Error that displays:
Unable to process request "gamenews.php"
What I'm doing wrong? Thanks.
Try like this
RewriteRule ^news/([0-9]+)/ gamenews.php?id=$1[L,R]
The rewrited url should go first
[0-9] means that second parameter should be a number
The order of your htaccess rules might be your problem in addition to your syntax. Unless I misunderstood your question.
Try this in your htaccess.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/(.*) gamenews.php?id=$1 [L]
RewriteRule ^(.*)/index\.php /$1/index [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
AddDefaultCharset UTF-8
Related
A very common problem, but couldn't fix the issue.
I want
http://website.de/page.php?module=helios
into
http://website.de/page/helios
I have tried lots of .htaccess code like this one, but still page sends to 404.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php?module=$1
Please provide some suggestions.
Try this rule in your site root .htaccess:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([^/]+)/?$ page.php?module=$1 [L,NC,QSA]
Try...
RewriteRule ^page/([^/]*)/$ /page.php?module=$1 [L]
Use this use your base path
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.*)$ page.php?module=$1
I have this rewrite rule in my htaccess script, but whenever i do a var_dump on $_GET it's empty, like the values from the url are not read in PHP.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?app=$1&page=$2&category=$3 [L]
</ifModule>
Example of url: .../index.php/main/featured/1
How can one fix this problem?
Thank you!
I believe these two conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
are not met as your URL is /index.php/main/featured/1. At least it did not work for me either. Can you either remove index.php part both from RewriteRule and your URL, making .htaccess:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?app=$1&page=$2&category=$3 [L]
</ifModule>
and navigating to URL /main/featured/1 or if you really need the index.php part, then uncomment/remove these conditions:
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
and continue using /index.php/main/featured/1 URL.
I am trying to do some rewrites with my .htaccess file
All I am trying to do is rewrite the url:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
WHICH I HAVE SUCCESSFULLY BEEN USING THE CODE BELOW FOR A WHILE NOW WITH NO ERRORS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ book.php?course=$1 [L]
Then, I tried adding another rewrite mod, below:
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
to shorten my urls by removing the .php extensions, and remove the traling slashes and it appears that they do not mix well for some reason. I am not very good with .Htaccess, so any help will be possitive.
Or if someone has another suggestion to rewrite:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
And
Rewrite .php files to remove extenstions and traling slashes..
it'd be so greately appreciated. Thank you in advance.
Figured it out!:
w/ a little a help from: Multiple conflicting htaccess RewriteRules
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ ./book.php?course=$1
I am looking for a way to access to:
http://myurl.com/?file=random_token
with
http://myurl.com/random_token/
I already read about mod_rewrite in the .htaccess but I don't know how to setup the pattern.
I tried this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)/$ /index.php?file=$1
It would be nice if you can help me.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /?file=$1 [L]
Try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCOnd %{REQUEST_FILENAME} !-d
RewriteRule /?([a-z-]+) index.php?file=$1 [L,QSA]
I use this htaccess to rewrite php extensions to .html.
I have a valid form which should be posting to an url, but I can't get the post data, I think this has something to do with the htaccess.
Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteBase /mypath/
# Rewrite to SEF URL's
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/(.*)\.html index.php?a=$1&b=$2&c=$3&d=$4 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)\.html index.php?a=$1&b=$2&c=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)\.html index.php?a=$1&b=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html index.php?a=$1 [QSA,L]
Does someone has a solution to solve my problem?
I guess, you must use a non-greedy regular expression. Replace .* with .*?
RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)\.html index.php?a=$1&b=$2&c=$3&d=$4 [QSA,L]
and the others appropriately.