我已尝试使用.htaccess
文件进行一些配置,但我真的无法找出问题所在。
我是.htacces文件的新手,我只想要一次简单的重写。
我如何重写:
~/Pages
文件夹http://host.com/Pages/page.php
http://host.com/page
~/Pages/Folder/page.php
变为:http://host.com/Folder/page
此外,我希望人们可以在不必考虑URL栏中的大写字母的情况下进行导航。
提前致谢。
编辑:
好的,我删除了扩展名。现在我想指向〜/ Pages / index.php
当有人访问网址http://HOST.com/index时
这是我到目前为止所得到的:
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]
问题:它一直指向/ urenreg / pages并且没有在链接中输入文件名(怀疑)
答案 0 :(得分:1)
例如
从以下位置移动.php文件:
public_html/*.php
要:
public_html/gta/*.php
您正在访问的是:
http://domain.com/gta/about
它试图在:
找到.php文件http://domain.com/gta/about.php
鉴于所有文件都在文件夹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]
答案 1 :(得分:0)
这就是我的结局。
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]