douzi9744 2014-03-21 12:34
浏览 25
已采纳

[edit]如何根据这些需要用.htaccess重写我的URL?

ThI've tried some configurations with my .htaccess file but I really can't find out what is going wrong.

I am new to the .htacces file and i just want 1 simple rewrite.

How do I rewrite this:

  • my pages are in my ~/Pages folder
  • I don't want to show: http://host.com/Pages/page.php
  • I want to rewrite this to: http://host.com/page
  • and that for example ~/Pages/Folder/page.php becomes: http://host.com/Folder/page

Also I want it possible that people can navigate without having to think about capital letters in the URL bar.

Thanks in advance.

EDIT:
ok i have the extension removed. now i'm trying to point to ~/Pages/index.php
When someone visits the url 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)

  • 写回答

2条回答 默认 最新

  • dongshengheng1013 2014-03-21 15:07
    关注

    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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化