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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程