dongpiansui8755 2017-01-19 00:49
浏览 25
已采纳

删除显示的网址的一部分,而不使用.htaccess更改$ _GET

Currently my .htaccess code sends the {REQUEST_URI} as a $_GET array to load.php where that page calls up the controllers for the request. For SEO purposes, I would like to remove a portion of the URL without changing the $_GET array that is sent to load.php.

For example if I have:

domain.com/products/product-name

I would like the URL to display:

domain.com/product-name

without changing the $_GET variable that is sent to load.php.

Any help would be greatly appreciated. I've included my current code.

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

CLARIFICATION:

$_GET[0] serves as a 'controller' variable which directs the application to open up the appropriate file. Therefore, I can't hardcode 'products' into $_GET[0] because that would constantly open up controllers/products.php instead of the appropriate file.

  • 写回答

1条回答 默认 最新

  • douyong8801 2017-01-19 03:25
    关注

    I would like the URL to display:

    domain.com/product-name

    without changing the $_GET variable that is sent to load.php.

    The only way to do what you're asking is to hardcode part of the URL in the substitution string of the rewriterule with products. See below. Then URL load.php will always receive products/somefile.

    RewriteEngine on
    
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^(.*)$ index.php?url=products/$1 [L,QSA]
    

    Update: This solution will work if you have one path/controller you want to substitute.

    You have to reference the controller some how. So if you don't have the controller in the request there is nothing to forward to the $_GET variable. PHP will not know where the request is supposed to go. There is nothing wrong with having that in the path and it should not affect your SEO.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?