简体   繁体   中英

htaccess tidy up url

So I have been trying to get my url to look better, but I can not get it to work as I want, so there might be some nice soul here that can help me out.

I need help with

ex: www.domain.com/project/index.php?p=settings&u=123&l=k

To look like www.domain.com/project/settings

I want index.php to be removed and all that comes after the first variable, in this case, p=settings, and also remove ?p=

I got this now

    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

旋转一下。

RewriteRule ^project/([^/]*)$ /project/index.php?p=$1&u=123&l=k [L, QSA]

There is the Possibility to redirect errorcodes

ErrorDocument 404 /index.php

In this way you can ask for www.domain.com/project/settings witch does not exist and instead of the error 404 you get redirected to /index.php

$uri_asked = explode("/", $_SERVER['PHP_SELF']);

then you have

$uri_asked[3]="project";
$uri_asked[4]="settings";

and you can build something like

include("www.domain.com/index.php?p=".$uri_asked[3]."&u=".$uri_asked[4]);

You can use this rule to discard unwanted query string:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\?p=([^&\s]+) [NC]
RewriteCond %{REQUEST_URI} !/system/ [NC]
RewriteRule ^(.*?)index\.php$ /$1%1? [R=301,NE,L]

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