[英][edit]How can I rewrite my URL with .htaccess according to these needs?
ThI've tried some configurations with my .htaccess
file but I really can't find out what is going wrong. 我已经使用
.htaccess
文件尝试了一些配置,但我真的无法找出问题所在。
I am new to the .htacces file and i just want 1 simple rewrite. 我是.htacces文件的新手,我只想要1个简单的重写。
How do I rewrite this: 我该如何重写:
~/Pages
folder ~/Pages
文件夹中 http://host.com/Pages/page.php
http://host.com/Pages/page.php
: http://host.com/Pages/page.php
http://host.com/page
http://host.com/page
: http://host.com/page
~/Pages/Folder/page.php
becomes: http://host.com/Folder/page
~/Pages/Folder/page.php
变为: http://host.com/Folder/page
: ~/Pages/Folder/page.php
Also I want it possible that people can navigate without having to think about capital letters in the URL bar. 我也希望人们可以导航而不必考虑URL栏中的大写字母。
Thanks in advance. 提前致谢。
EDIT: 编辑:
ok i have the extension removed. 好的,我删除了扩展名。 now i'm trying to point to ~/Pages/index.php
现在我试图指向〜/ Pages / index.php
When someone visits the url http://HOST.com/index 有人访问网址http://HOST.com/index时
This is what i got so far: 这是我到目前为止所得到的:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /urenreg/
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_URI} !urenreg/Pages/
RewriteCond ^(.+?)?$ Pages/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)?$ /$1.php [L]
problem: it keeps pointing to /urenreg/pages and doesn't enter the file name in the link (suspecting) 问题:它一直指向/ urenreg / pages,并且未在链接中输入文件名(怀疑)
for example 例如
Move your .php files from: 从以下位置移动您的.php文件:
public_html/*.php
To: 至:
public_html/gta/*.php
What happens is that you're accessing: 发生的情况是您正在访问:
http://domain.com/gta/about
And it tries to find the .php file at: 然后尝试在以下位置找到.php文件:
http://domain.com/gta/about.php
Given that all files are on the folder gta you .htaccess can be what you exactly have, but needs to be on the public_html folder and there should be NO .htaccess inside the gta folder: 鉴于所有文件都在文件夹gta上,因此您可以准确地拥有.htaccess文件,但必须将其放在public_html文件夹中,并且gta文件夹内不应有.htaccess文件:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
This is how i ended up. 这就是我最终的方式。
Options +FollowSymLinks -MultiViews -Indexes
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /urenreg/
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/urenreg/$1.php -f
RewriteRule ^(.+?)/?$ /urenreg/$1.php [L]
RewriteCond %{REQUEST_URI} !lib/
RewriteCond %{REQUEST_URI} !dist/
RewriteCond %{REQUEST_URI} !js/
RewriteCond %{REQUEST_URI} !grunt/
RewriteCond %{REQUEST_URI} !less/
RewriteCond %{REQUEST_URI} !test-infra/
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{REQUEST_URI} !urenreg/Pages/
RewriteRule (.*) Pages/$1/ [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.