Simple RewriteRule causing problems - php

We want this type of URL: www.ourdomain.com/dev/kunde-first/service
to be rewritten to: www.ourdomain.com/dev/kunde-first/inhalt.php?id=service
and are using this in our .htaccess:
RewriteEngine On
RewriteBase /dev/kunde-first/
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|ico|txt|html|htm|xml|eot|woff|ttf|svg)$
RewriteCond %{REQUEST_FILENAME} !.(scripts/[^/]*)$
RewriteRule ^([A-Za-z0-9-]+) inhalt.php?id=$1 [NC,L] # process navigation
However, when we fetch $_GET['id'] we get 'inhalt' instead of 'service'.
Any help would be greatly appreciated!

Try this rule with correct regex:
RewriteEngine On
RewriteBase /dev/kunde-first/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/?$ inhalt.php?id=$1 [NC,L,QSA]

Related

.htaccess route all except if contains word

So at the moment, any missing pages (404) get redirected to domain.com/search.php and carries the query parameters
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ search.php [QSA,L]
This works great, however, I have an edge case for domain.com/submit where I need it to redirect to domain.com/submit.php
Can't seem to figure out how to do it.
Thanks in advance
You can use this :
RewriteEngine On
RewriteBase /
#rewrite /submit to /submit.php
RewriteRule ^submit/?$ submit.php [L,NC]
#rewrite other non-existent URIs to /search.pho
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ search.php [QSA,L]
Like this, I suggest adding NC so it's case-insensitive:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^submit?$ submit.php [NC, L]
RewriteRule ^(.+)$ search.php [NC, QSA,L]

Dynamic url change into seo friendly url

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

Rookie Url Rewriting 2

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.

Htaccess conflicts

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

php mod_rewrite Permalinks

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]

Categories