htaccess rewrite php to html, no post method? - php

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.

Related

Rewrite Rule for id .htaccess

Is there any possibility to rewrite url's with get variables globally, instead of specific files?
Changing
http://example.com/{something}?id=1
To:
http://example.com/{something}/id/1
Or without the word id:
http://example.com/{something}/1
This is what I got so far:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.phtml
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.phtml
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
With this I could remove the .phtml extension
I hope there is a specific answer for this!
I am assuming something to be a php file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/id/([\d]+)$ $1.php?id=$2 [L] #with id in between
or
RewriteRule ^([\w-]+)/([\d]+)$ $1.php?id=$2 [L] #without id in between
You have to make sure rules are not conflicting.

.htaccess: Rewrite dynamic url with static url

I want to enter http://localhost:81/admin/dashboard in my browser but the request should be http://localhost:81/admin/index.php?page=dashboard.
The mod_rewrite is enabled and i tried this in the .htaccess but it didn't work. The .htaccess is located in htdocs/admin/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ index.php?page=$1 [NC]
You can match the trailing slash optionally by adding a ? next to it in the pattern :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [NC]

htaccess rewrite rule for subfolder (nice url)

I have trying to figure out how to get working in subfolder "admin" the same thing which works in root dir, problem is I don't know how to do that.
Currently I have:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]
# /
RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
RewriteRule ^(.+[^/])$ /$1/ [R=301]
Now it works like:
http://example.com/page translate into http://example.com/?arg=page
What I would like to do in addition is this:
http://example.com/admin/page translate into http://example.com/admin/?arg=page
I don't know at all how to make that happen, can somebody help me please?
Thanks
You can use these rules with appropriate RewriteBase:
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]
Or just add
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin/(.*)$ admin/index.php?arg=$1 [L,QSA]

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.

Categories