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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用