普通网友 2016-05-29 23:06
浏览 48
已采纳

子域上GET参数的Mod重写

I'm trying to rewrite a subdomain (NOT REDIRECT) to a $_GET parameter as such:

Desired result:

http://go.example.bz/link/abcde   ->   http://example.bz/go/link?id=abcde
or
http://go.example.bz/hrm/employee/8   ->   http://example.bz/go/hrm/employee?id=8

What's currently working:

http://example.bz/go/link/abcde -> http://example.bz/go/link?id=abcde
and
http://example.bz/go/hrm/employee/8 -> http://example.bz/go/hrm/employee?id=8

with this .htaccess in the root:

RewriteEngine On

RewriteRule ^go/link.php/([^/\.]+)/?$ go/link.php?id=$1 [L]
RewriteRule ^go/hrm/employee.php/([^/\.]+)/?$ go/hrm/employee.php?parameter=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

AddCharset UTF-8 .php
Options -Indexes

and this is how I redirect the subdomain:

<VirtualHost *:80> 
   Servername go.example.bz DocumentRoot /var/www/go
</VirtualHost>

I do not want to redirect to the -> destination, rather to keep the http://go.example.bz/link/abcde url but have the results of the /link?abcde

  • 写回答

4条回答 默认 最新

  • duanliaozhi2915 2016-06-01 20:27
    关注

    I figured that my problem came from not remove .php extension from subdomain URLs of which I found an answer here https://css-tricks.com/forums/topic/remove-php-extension-from-subdomain-urls/ and then I alternated my RewriteRules as such:

    RewriteEngine On
    
    RewriteRule ^go/link/([^/\.]+)/?$ go/link.php?id=$1 [L]
    RewriteRule ^go/hrm/employee/([^/\.]+)/?$ go/hrm/employee.php?id=$1 [L]
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^go\.example\.bz$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.go\.example\.bz$
    RewriteRule ^/?$ "http\:\/\/tgc\.bz\/go" [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^\.]+)/$ $1.php
    
    AddCharset UTF-8 .php
    Options -Indexes
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面