简体   繁体   中英

Re-Writing URL with .htaccess don't works with multiple re-writes dynamic or static

I have trouble in making fancy URLs with .htaccess .

I'm saving titles in database like "name-of-a-title" but problems start when I try to access it from URL, it doesn't show me the CSS, only the content.

This URL for blog works like:

http://example.com/blog?title=page-title

and I need a URL like this

http://example.com/blog/post-title

Here is my file, I'm a beginner.

<files .htaccess>
order allow,deny
deny from all
</files>

RewriteEngine On
RewriteRule ^blog$ blog.php
RewriteRule ^blog/$ blog.php
RewriteRule ^blog/([^/]*)$ /blog?title=$1 [L]

RewriteEngine On
RewriteRule ^category/([^/]*)$ category.php?$1 [L]

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # To externally redirect /dir/abc.php to /dir/abc
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
    RewriteRule ^ /%1 [R=301,L,NE]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [QSA,NC,L]
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^\.]+)$ $1.php [QSA,NC,L]
</IfModule>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^my-webiste.com
RewriteRule (.*) http://www.my-website.com/$1 [R=301,L]

RewriteEngine On
ErrorDocument 404 /404.php

您只需要更新HTML,以便它使用绝对链接来引用CSS,图像等。有了您喜欢的URL,浏览器现在就从/blog/开始,而不是从root查找。

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