简体   繁体   中英

htaccess get parameters for seo url

// Sorry for the grammar mistakes and any other thing that's wrong, English isn't my mother tongue(don't know if I spelled it good).

I have made SEO friendly URLs with htaccess. The only problem is, that I always would get information out the url(using GET) and now with the SEO friendly URLs I can't do that.

My previous url was this:

http://rasolutions.eu/blogitem?id=2

So in PHP it would be $_GET['id'] and it would be 2. But now that I've got SEO friendly urls it's this:

http://rasolutions.eu/blogitem/2/

And now my PHP script can't see where he would get the ID from, so it will return me back to the homepage.

I have Googled that you need to use (.*) in htaccess but I don't know where or how. My htaccess code is this atm:

Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]
    RewriteRule    ^blog/(.*)([0-9]+)/$    blog.php?page=$1    [NC,L]
    RewriteRule    ^blogitem/(.*)([0-9]+)/$    blogitem.php?id=$1    [NC,L]

The last two rules should be correct without that (.*) according to the example syntax you posted. And you have to take care of the trailing slash ( / ) in a flexible manner:

Options +MultiViews 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^(.*)$ http://rasolutions.eu$1 [R=301,L]

RewriteRule ^blog/([0-9]*)/?$        blog.php?page=$1    [NC,L]
RewriteRule ^blogitem/([0-9]*)/?$    blogitem.php?id=$1    [NC,L]

In general it is a very good idea to use RewriteLogging if you have access to it. It helps you understand exactly what is going on inside the rewriting engine at each single sub step instead of having to guess what happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM