15

here is my code for .htaccess file

Options -Indexes
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^([a-z0-9]+)$ /profile.php?username=$1 [L]
RewriteRule ^([a-z0-9]+)$ /display.php?page=$1 [L]

For the first one it works correctly and is displaying like this: www.site.com/user

The second one is not working, normally is displaying like this www.site.com/display.php?page=10. I want to display the page like this www.site.com/article I tried different things and no result. Please tell me how to make to work with multiple rules. Also please give me an advice on how to use this functionalities in php because I think I done something not really good. My php code for using this rule is:

<p><a class="button" href="/<?php echo $user_data['username']; ?>"> Profile</a></p>

It works, but maybe is a better way to make a link to take advantage of htaccess.

4

4 に答える 4

2

私はそれをこのように動作させました。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/index.php/$1 [C]

#second condition and rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/subdir/index.php/$1 [L]
于 2016-07-01T05:30:48.180 に答える
1

多くの試行錯誤の後:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?\/)*?([a-z\.\-]+)(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1$2$4 [NC]

# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [L]
</IfModule>

私が受け取ったヒント[L]は、最後のルールを示し、[N]続行を意味するというものでした。

于 2018-10-15T15:59:42.503 に答える